diff options
| author | QMK Bot <hello@qmk.fm> | 2022-02-12 10:29:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-12 18:29:31 +0000 |
| commit | 63646e8906e062d1c1de3925cba70c4e3426a855 (patch) | |
| tree | 4e91648b77b838e1125cf86331d7e84bde6d07a9 /drivers/oled | |
| parent | afcdd7079c774dec2aa4b7f2d08adf8b7310919b (diff) | |
Format code according to conventions (#16322)
Diffstat (limited to 'drivers/oled')
| -rw-r--r-- | drivers/oled/oled_driver.h | 22 | ||||
| -rw-r--r-- | drivers/oled/ssd1306_sh1106.c | 49 |
2 files changed, 43 insertions, 28 deletions
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h index 3b56d370dc..918b837f07 100644 --- a/drivers/oled/oled_driver.h +++ b/drivers/oled/oled_driver.h | |||
| @@ -34,16 +34,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 34 | # define OLED_DISPLAY_HEIGHT 64 | 34 | # define OLED_DISPLAY_HEIGHT 64 |
| 35 | # endif | 35 | # endif |
| 36 | # ifndef OLED_MATRIX_SIZE | 36 | # ifndef OLED_MATRIX_SIZE |
| 37 | # define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed) | 37 | # define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 1024 (compile time mathed) |
| 38 | # endif | 38 | # endif |
| 39 | # ifndef OLED_BLOCK_TYPE | 39 | # ifndef OLED_BLOCK_TYPE |
| 40 | # define OLED_BLOCK_TYPE uint16_t | 40 | # define OLED_BLOCK_TYPE uint16_t |
| 41 | # endif | 41 | # endif |
| 42 | # ifndef OLED_BLOCK_COUNT | 42 | # ifndef OLED_BLOCK_COUNT |
| 43 | # define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed) | 43 | # define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 32 (compile time mathed) |
| 44 | # endif | 44 | # endif |
| 45 | # ifndef OLED_BLOCK_SIZE | 45 | # ifndef OLED_BLOCK_SIZE |
| 46 | # define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) | 46 | # define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) |
| 47 | # endif | 47 | # endif |
| 48 | # ifndef OLED_COM_PINS | 48 | # ifndef OLED_COM_PINS |
| 49 | # define OLED_COM_PINS COM_PINS_ALT | 49 | # define OLED_COM_PINS COM_PINS_ALT |
| @@ -68,7 +68,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 68 | // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: | 68 | // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: |
| 69 | // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 } | 69 | // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120 } |
| 70 | // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 } | 70 | // #define OLED_TARGET_MAP { 56, 120, 48, 112, 40, 104, 32, 96, 24, 88, 16, 80, 8, 72, 0, 64 } |
| 71 | #else // defined(OLED_DISPLAY_128X64) | 71 | #else // defined(OLED_DISPLAY_128X64) |
| 72 | // Default 128x32 | 72 | // Default 128x32 |
| 73 | # ifndef OLED_DISPLAY_WIDTH | 73 | # ifndef OLED_DISPLAY_WIDTH |
| 74 | # define OLED_DISPLAY_WIDTH 128 | 74 | # define OLED_DISPLAY_WIDTH 128 |
| @@ -77,16 +77,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 77 | # define OLED_DISPLAY_HEIGHT 32 | 77 | # define OLED_DISPLAY_HEIGHT 32 |
| 78 | # endif | 78 | # endif |
| 79 | # ifndef OLED_MATRIX_SIZE | 79 | # ifndef OLED_MATRIX_SIZE |
| 80 | # define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed) | 80 | # define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH) // 512 (compile time mathed) |
| 81 | # endif | 81 | # endif |
| 82 | # ifndef OLED_BLOCK_TYPE | 82 | # ifndef OLED_BLOCK_TYPE |
| 83 | # define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only | 83 | # define OLED_BLOCK_TYPE uint16_t // Type to use for segmenting the oled display for smart rendering, use unsigned types only |
| 84 | # endif | 84 | # endif |
| 85 | # ifndef OLED_BLOCK_COUNT | 85 | # ifndef OLED_BLOCK_COUNT |
| 86 | # define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed) | 86 | # define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8) // 16 (compile time mathed) |
| 87 | # endif | 87 | # endif |
| 88 | # ifndef OLED_BLOCK_SIZE | 88 | # ifndef OLED_BLOCK_SIZE |
| 89 | # define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) | 89 | # define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT) // 32 (compile time mathed) |
| 90 | # endif | 90 | # endif |
| 91 | # ifndef OLED_COM_PINS | 91 | # ifndef OLED_COM_PINS |
| 92 | # define OLED_COM_PINS COM_PINS_SEQ | 92 | # define OLED_COM_PINS COM_PINS_SEQ |
| @@ -105,7 +105,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 105 | // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: | 105 | // If OLED_BLOCK_TYPE is uint8_t, these tables would look like: |
| 106 | // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } | 106 | // #define OLED_SOURCE_MAP { 0, 8, 16, 24, 32, 40, 48, 56 } |
| 107 | // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 } | 107 | // #define OLED_TARGET_MAP { 48, 32, 16, 0, 56, 40, 24, 8 } |
| 108 | #endif // defined(OLED_DISPLAY_CUSTOM) | 108 | #endif // defined(OLED_DISPLAY_CUSTOM) |
| 109 | 109 | ||
| 110 | #if !defined(OLED_IC) | 110 | #if !defined(OLED_IC) |
| 111 | # define OLED_IC OLED_IC_SSD1306 | 111 | # define OLED_IC OLED_IC_SSD1306 |
| @@ -180,7 +180,7 @@ typedef enum { | |||
| 180 | OLED_ROTATION_0 = 0, | 180 | OLED_ROTATION_0 = 0, |
| 181 | OLED_ROTATION_90 = 1, | 181 | OLED_ROTATION_90 = 1, |
| 182 | OLED_ROTATION_180 = 2, | 182 | OLED_ROTATION_180 = 2, |
| 183 | OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180 | 183 | OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180 |
| 184 | } oled_rotation_t; | 184 | } oled_rotation_t; |
| 185 | 185 | ||
| 186 | // Initialize the oled display, rotating the rendered output based on the define passed in. | 186 | // Initialize the oled display, rotating the rendered output based on the define passed in. |
| @@ -262,7 +262,7 @@ void oled_write_raw_P(const char *data, uint16_t size); | |||
| 262 | # define oled_write_P(data, invert) oled_write(data, invert) | 262 | # define oled_write_P(data, invert) oled_write(data, invert) |
| 263 | # define oled_write_ln_P(data, invert) oled_write(data, invert) | 263 | # define oled_write_ln_P(data, invert) oled_write(data, invert) |
| 264 | # define oled_write_raw_P(data, size) oled_write_raw(data, size) | 264 | # define oled_write_raw_P(data, size) oled_write_raw(data, size) |
| 265 | #endif // defined(__AVR__) | 265 | #endif // defined(__AVR__) |
| 266 | 266 | ||
| 267 | // Can be used to manually turn on the screen if it is off | 267 | // Can be used to manually turn on the screen if it is off |
| 268 | // Returns true if the screen was on or turns on | 268 | // Returns true if the screen was on or turns on |
diff --git a/drivers/oled/ssd1306_sh1106.c b/drivers/oled/ssd1306_sh1106.c index d9bd3c14bd..30cfeb5648 100644 --- a/drivers/oled/ssd1306_sh1106.c +++ b/drivers/oled/ssd1306_sh1106.c | |||
| @@ -53,7 +53,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 53 | #define PAGE_ADDR 0x22 | 53 | #define PAGE_ADDR 0x22 |
| 54 | #define PAM_SETCOLUMN_LSB 0x00 | 54 | #define PAM_SETCOLUMN_LSB 0x00 |
| 55 | #define PAM_SETCOLUMN_MSB 0x10 | 55 | #define PAM_SETCOLUMN_MSB 0x10 |
| 56 | #define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7 | 56 | #define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7 |
| 57 | 57 | ||
| 58 | // Hardware Configuration Commands | 58 | // Hardware Configuration Commands |
| 59 | #define DISPLAY_START_LINE 0x40 | 59 | #define DISPLAY_START_LINE 0x40 |
| @@ -97,9 +97,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 97 | #define I2C_DATA 0x40 | 97 | #define I2C_DATA 0x40 |
| 98 | #if defined(__AVR__) | 98 | #if defined(__AVR__) |
| 99 | # define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) | 99 | # define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) |
| 100 | #else // defined(__AVR__) | 100 | #else // defined(__AVR__) |
| 101 | # define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) | 101 | # define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) |
| 102 | #endif // defined(__AVR__) | 102 | #endif // defined(__AVR__) |
| 103 | #define I2C_TRANSMIT(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) | 103 | #define I2C_TRANSMIT(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT) |
| 104 | #define I2C_WRITE_REG(mode, data, size) i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), mode, data, size, OLED_I2C_TIMEOUT) | 104 | #define I2C_WRITE_REG(mode, data, size) i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), mode, data, size, OLED_I2C_TIMEOUT) |
| 105 | 105 | ||
| @@ -119,7 +119,7 @@ bool oled_inverted = false; | |||
| 119 | uint8_t oled_brightness = OLED_BRIGHTNESS; | 119 | uint8_t oled_brightness = OLED_BRIGHTNESS; |
| 120 | oled_rotation_t oled_rotation = 0; | 120 | oled_rotation_t oled_rotation = 0; |
| 121 | uint8_t oled_rotation_width = 0; | 121 | uint8_t oled_rotation_width = 0; |
| 122 | uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values | 122 | uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values |
| 123 | uint8_t oled_scroll_start = 0; | 123 | uint8_t oled_scroll_start = 0; |
| 124 | uint8_t oled_scroll_end = 7; | 124 | uint8_t oled_scroll_end = 7; |
| 125 | #if OLED_TIMEOUT > 0 | 125 | #if OLED_TIMEOUT > 0 |
| @@ -190,7 +190,7 @@ bool oled_init(oled_rotation_t rotation) { | |||
| 190 | #if (OLED_IC != OLED_IC_SH1106) | 190 | #if (OLED_IC != OLED_IC_SH1106) |
| 191 | // MEMORY_MODE is unsupported on SH1106 (Page Addressing only) | 191 | // MEMORY_MODE is unsupported on SH1106 (Page Addressing only) |
| 192 | MEMORY_MODE, | 192 | MEMORY_MODE, |
| 193 | 0x00, // Horizontal addressing mode | 193 | 0x00, // Horizontal addressing mode |
| 194 | #endif | 194 | #endif |
| 195 | }; | 195 | }; |
| 196 | if (I2C_TRANSMIT_P(display_setup1) != I2C_STATUS_SUCCESS) { | 196 | if (I2C_TRANSMIT_P(display_setup1) != I2C_STATUS_SUCCESS) { |
| @@ -232,8 +232,12 @@ bool oled_init(oled_rotation_t rotation) { | |||
| 232 | return true; | 232 | return true; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | __attribute__((weak)) oled_rotation_t oled_init_kb(oled_rotation_t rotation) { return rotation; } | 235 | __attribute__((weak)) oled_rotation_t oled_init_kb(oled_rotation_t rotation) { |
| 236 | __attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return rotation; } | 236 | return rotation; |
| 237 | } | ||
| 238 | __attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { | ||
| 239 | return rotation; | ||
| 240 | } | ||
| 237 | 241 | ||
| 238 | void oled_clear(void) { | 242 | void oled_clear(void) { |
| 239 | memset(oled_buffer, 0, sizeof(oled_buffer)); | 243 | memset(oled_buffer, 0, sizeof(oled_buffer)); |
| @@ -306,9 +310,9 @@ void oled_render(void) { | |||
| 306 | // Set column & page position | 310 | // Set column & page position |
| 307 | static uint8_t display_start[] = {I2C_CMD, COLUMN_ADDR, 0, OLED_DISPLAY_WIDTH - 1, PAGE_ADDR, 0, OLED_DISPLAY_HEIGHT / 8 - 1}; | 311 | static uint8_t display_start[] = {I2C_CMD, COLUMN_ADDR, 0, OLED_DISPLAY_WIDTH - 1, PAGE_ADDR, 0, OLED_DISPLAY_HEIGHT / 8 - 1}; |
| 308 | if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { | 312 | if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) { |
| 309 | calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start | 313 | calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start |
| 310 | } else { | 314 | } else { |
| 311 | calc_bounds_90(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start | 315 | calc_bounds_90(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start |
| 312 | } | 316 | } |
| 313 | 317 | ||
| 314 | // Send column & page position | 318 | // Send column & page position |
| @@ -368,7 +372,8 @@ void oled_advance_page(bool clearPageRemainder) { | |||
| 368 | remaining = remaining / OLED_FONT_WIDTH; | 372 | remaining = remaining / OLED_FONT_WIDTH; |
| 369 | 373 | ||
| 370 | // Write empty character until next line | 374 | // Write empty character until next line |
| 371 | while (remaining--) oled_write_char(' ', false); | 375 | while (remaining--) |
| 376 | oled_write_char(' ', false); | ||
| 372 | } else { | 377 | } else { |
| 373 | // Next page index out of bounds? | 378 | // Next page index out of bounds? |
| 374 | if (index + remaining >= OLED_MATRIX_SIZE) { | 379 | if (index + remaining >= OLED_MATRIX_SIZE) { |
| @@ -419,7 +424,7 @@ void oled_write_char(const char data, bool invert) { | |||
| 419 | _Static_assert(sizeof(font) >= ((OLED_FONT_END + 1 - OLED_FONT_START) * OLED_FONT_WIDTH), "OLED_FONT_END references outside array"); | 424 | _Static_assert(sizeof(font) >= ((OLED_FONT_END + 1 - OLED_FONT_START) * OLED_FONT_WIDTH), "OLED_FONT_END references outside array"); |
| 420 | 425 | ||
| 421 | // set the reder buffer data | 426 | // set the reder buffer data |
| 422 | uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index | 427 | uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index |
| 423 | if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) { | 428 | if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) { |
| 424 | memset(oled_cursor, 0x00, OLED_FONT_WIDTH); | 429 | memset(oled_cursor, 0x00, OLED_FONT_WIDTH); |
| 425 | } else { | 430 | } else { |
| @@ -545,7 +550,7 @@ void oled_write_raw_P(const char *data, uint16_t size) { | |||
| 545 | oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE)); | 550 | oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE)); |
| 546 | } | 551 | } |
| 547 | } | 552 | } |
| 548 | #endif // defined(__AVR__) | 553 | #endif // defined(__AVR__) |
| 549 | 554 | ||
| 550 | bool oled_on(void) { | 555 | bool oled_on(void) { |
| 551 | if (!oled_initialized) { | 556 | if (!oled_initialized) { |
| @@ -595,7 +600,9 @@ bool oled_off(void) { | |||
| 595 | return !oled_active; | 600 | return !oled_active; |
| 596 | } | 601 | } |
| 597 | 602 | ||
| 598 | bool is_oled_on(void) { return oled_active; } | 603 | bool is_oled_on(void) { |
| 604 | return oled_active; | ||
| 605 | } | ||
| 599 | 606 | ||
| 600 | uint8_t oled_set_brightness(uint8_t level) { | 607 | uint8_t oled_set_brightness(uint8_t level) { |
| 601 | if (!oled_initialized) { | 608 | if (!oled_initialized) { |
| @@ -613,7 +620,9 @@ uint8_t oled_set_brightness(uint8_t level) { | |||
| 613 | return oled_brightness; | 620 | return oled_brightness; |
| 614 | } | 621 | } |
| 615 | 622 | ||
| 616 | uint8_t oled_get_brightness(void) { return oled_brightness; } | 623 | uint8_t oled_get_brightness(void) { |
| 624 | return oled_brightness; | ||
| 625 | } | ||
| 617 | 626 | ||
| 618 | // Set the specific 8 lines rows of the screen to scroll. | 627 | // Set the specific 8 lines rows of the screen to scroll. |
| 619 | // 0 is the default for start, and 7 for end, which is the entire | 628 | // 0 is the default for start, and 7 for end, which is the entire |
| @@ -693,7 +702,9 @@ bool oled_scroll_off(void) { | |||
| 693 | return !oled_scrolling; | 702 | return !oled_scrolling; |
| 694 | } | 703 | } |
| 695 | 704 | ||
| 696 | bool is_oled_scrolling(void) { return oled_scrolling; } | 705 | bool is_oled_scrolling(void) { |
| 706 | return oled_scrolling; | ||
| 707 | } | ||
| 697 | 708 | ||
| 698 | bool oled_invert(bool invert) { | 709 | bool oled_invert(bool invert) { |
| 699 | if (!oled_initialized) { | 710 | if (!oled_initialized) { |
| @@ -777,5 +788,9 @@ void oled_task(void) { | |||
| 777 | #endif | 788 | #endif |
| 778 | } | 789 | } |
| 779 | 790 | ||
| 780 | __attribute__((weak)) bool oled_task_kb(void) { return oled_task_user(); } | 791 | __attribute__((weak)) bool oled_task_kb(void) { |
| 781 | __attribute__((weak)) bool oled_task_user(void) { return true; } | 792 | return oled_task_user(); |
| 793 | } | ||
| 794 | __attribute__((weak)) bool oled_task_user(void) { | ||
| 795 | return true; | ||
| 796 | } | ||
