summaryrefslogtreecommitdiff
path: root/users/drashna/oled/sh110x.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/drashna/oled/sh110x.c')
-rw-r--r--users/drashna/oled/sh110x.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/users/drashna/oled/sh110x.c b/users/drashna/oled/sh110x.c
index aa081ca732..9fed5a9d1a 100644
--- a/users/drashna/oled/sh110x.c
+++ b/users/drashna/oled/sh110x.c
@@ -52,7 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PAGE_ADDR 0x22
#define PAM_SETCOLUMN_LSB 0x00
#define PAM_SETCOLUMN_MSB 0x10
-#define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7
+#define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7
// Hardware Configuration Commands
#define DISPLAY_START_LINE 0x40
@@ -109,9 +109,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define I2C_DATA 0x40
#if defined(__AVR__)
# define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT)
-#else // defined(__AVR__)
+#else // defined(__AVR__)
# define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT)
-#endif // defined(__AVR__)
+#endif // defined(__AVR__)
#define I2C_TRANSMIT(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT)
#define I2C_WRITE_REG(mode, data, size) i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), mode, data, size, OLED_I2C_TIMEOUT)
@@ -122,7 +122,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// parts of the display unusable or don't get cleared correctly
// and also allows for drawing & inverting
uint8_t oled_buffer[OLED_MATRIX_SIZE];
-uint8_t * oled_cursor;
+uint8_t *oled_cursor;
OLED_BLOCK_TYPE oled_dirty = 0;
bool oled_initialized = false;
bool oled_active = false;
@@ -131,7 +131,7 @@ bool oled_inverted = false;
uint8_t oled_brightness = OLED_BRIGHTNESS;
oled_rotation_t oled_rotation = 0;
uint8_t oled_rotation_width = 0;
-uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values
+uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values
uint8_t oled_scroll_start = 0;
uint8_t oled_scroll_end = 7;
#if OLED_TIMEOUT > 0
@@ -261,8 +261,12 @@ bool oled_init(oled_rotation_t rotation) {
return true;
}
-__attribute__((weak)) oled_rotation_t oled_init_kb(oled_rotation_t rotation) { return rotation; }
-__attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return rotation; }
+__attribute__((weak)) oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
+ return rotation;
+}
+__attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) {
+ return rotation;
+}
void oled_clear(void) {
memset(oled_buffer, 0, sizeof(oled_buffer));
@@ -299,9 +303,9 @@ static void calc_bounds_90(uint8_t update_start, uint8_t *cmd_array) {
// Only the Page Addressing Mode is supported
uint8_t start_page = bottom_block_top_page - (OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT / 8);
uint8_t start_column = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8;
- cmd_array[0] = PAM_PAGE_ADDR | start_page;
- cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f);
- cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f);
+ cmd_array[0] = PAM_PAGE_ADDR | start_page;
+ cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f);
+ cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f);
}
uint8_t crot(uint8_t a, int8_t n) {
@@ -339,9 +343,9 @@ void oled_render(void) {
// Set column & page position
static uint8_t display_start[] = {I2C_CMD, PAM_PAGE_ADDR, PAM_SETCOLUMN_LSB, PAM_SETCOLUMN_MSB};
if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
- calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
+ calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
} else {
- calc_bounds_90(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
+ calc_bounds_90(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
}
// Send column & page position
@@ -369,7 +373,7 @@ void oled_render(void) {
// For SH1106 or SH1107 the data chunk must be split into separate pieces for each page
const uint8_t columns_in_block = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) / OLED_DISPLAY_HEIGHT * 8;
- const uint8_t num_pages = OLED_BLOCK_SIZE / columns_in_block;
+ const uint8_t num_pages = OLED_BLOCK_SIZE / columns_in_block;
for (uint8_t i = 0; i < num_pages; ++i) {
// Send column & page position for all pages except the first one
if (i > 0) {
@@ -414,7 +418,8 @@ void oled_advance_page(bool clearPageRemainder) {
remaining = remaining / OLED_FONT_WIDTH;
// Write empty character until next line
- while (remaining--) oled_write_char(' ', false);
+ while (remaining--)
+ oled_write_char(' ', false);
} else {
// Next page index out of bounds?
if (index + remaining >= OLED_MATRIX_SIZE) {
@@ -465,7 +470,7 @@ void oled_write_char(const char data, bool invert) {
_Static_assert(sizeof(font) >= ((OLED_FONT_END + 1 - OLED_FONT_START) * OLED_FONT_WIDTH), "OLED_FONT_END references outside array");
// set the reder buffer data
- uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
+ uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) {
memset(oled_cursor, 0x00, OLED_FONT_WIDTH);
} else {
@@ -610,7 +615,7 @@ void oled_write_raw_P(const char *data, uint16_t size) {
oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
}
}
-#endif // defined(__AVR__)
+#endif // defined(__AVR__)
bool oled_on(void) {
if (!oled_initialized) {
@@ -660,7 +665,9 @@ bool oled_off(void) {
return !oled_active;
}
-bool is_oled_on(void) { return oled_active; }
+bool is_oled_on(void) {
+ return oled_active;
+}
uint8_t oled_set_brightness(uint8_t level) {
if (!oled_initialized) {
@@ -678,7 +685,9 @@ uint8_t oled_set_brightness(uint8_t level) {
return oled_brightness;
}
-uint8_t oled_get_brightness(void) { return oled_brightness; }
+uint8_t oled_get_brightness(void) {
+ return oled_brightness;
+}
// Set the specific 8 lines rows of the screen to scroll.
// 0 is the default for start, and 7 for end, which is the entire
@@ -758,7 +767,9 @@ bool oled_scroll_off(void) {
return !oled_scrolling;
}
-bool is_oled_scrolling(void) { return oled_scrolling; }
+bool is_oled_scrolling(void) {
+ return oled_scrolling;
+}
bool oled_invert(bool invert) {
if (!oled_initialized) {
@@ -842,6 +853,9 @@ void oled_task(void) {
#endif
}
-
-__attribute__((weak)) bool oled_task_kb(void) { return oled_task_user(); }
-__attribute__((weak)) bool oled_task_user(void) { return true; }
+__attribute__((weak)) bool oled_task_kb(void) {
+ return oled_task_user();
+}
+__attribute__((weak)) bool oled_task_user(void) {
+ return true;
+}