From d2856529ce936d7cdf9d4c3adb71408a1172f036 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 2 Oct 2018 17:24:22 -0400 Subject: [PATCH 1/6] add suppport for the joystiic, adjust planck i2c settings --- drivers/arm/i2c_master.c | 11 +- drivers/arm/i2c_master.h | 1 + drivers/qwiic/joystiic.c | 184 ++++++++++++++++++++++++++++++++ drivers/qwiic/joystiic.h | 26 +++++ keyboards/planck/rev6/halconf.h | 2 +- keyboards/planck/rev6/mcuconf.h | 2 +- keyboards/planck/rev6/rev6.c | 3 + keyboards/planck/rev6/rules.mk | 2 +- 8 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 drivers/qwiic/joystiic.c create mode 100644 drivers/qwiic/joystiic.h diff --git a/drivers/arm/i2c_master.c b/drivers/arm/i2c_master.c index 2a7badd351..f53cb394a7 100644 --- a/drivers/arm/i2c_master.c +++ b/drivers/arm/i2c_master.c @@ -43,7 +43,12 @@ static const I2CConfig i2cconfig = { void i2c_init(void) { - palSetGroupMode(GPIOB, GPIOB_PIN6 | GPIOB_PIN7, 0, PAL_MODE_INPUT); // Try releasing special pins for a short time + //palSetGroupMode(GPIOB, GPIOB_PIN6 | GPIOB_PIN7, 0, PAL_MODE_INPUT); + + // Try releasing special pins for a short time + palSetPadMode(GPIOB, 6, PAL_MODE_INPUT); + palSetPadMode(GPIOB, 7, PAL_MODE_INPUT); + chThdSleepMilliseconds(10); palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); @@ -74,6 +79,10 @@ uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t ti return i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, MS2ST(timeout)); } +uint8_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length) { + return i2cMasterTransmitTimeout(&I2C_DRIVER, address/2, tx_body, tx_length, rx_body, rx_length, MS2ST(100)); +} + uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) { i2c_address = devaddr; diff --git a/drivers/arm/i2c_master.h b/drivers/arm/i2c_master.h index 591fa7f77d..392760328f 100644 --- a/drivers/arm/i2c_master.h +++ b/drivers/arm/i2c_master.h @@ -34,6 +34,7 @@ void i2c_init(void); uint8_t i2c_start(uint8_t address); uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout); uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout); +uint8_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length); uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout); uint8_t i2c_readReg(uint8_t devaddr, uint8_t* regaddr, uint8_t* data, uint16_t length, uint16_t timeout); uint8_t i2c_stop(uint16_t timeout); diff --git a/drivers/qwiic/joystiic.c b/drivers/qwiic/joystiic.c new file mode 100644 index 0000000000..ac97a22cd7 --- /dev/null +++ b/drivers/qwiic/joystiic.c @@ -0,0 +1,184 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "joystiic.h" +#include "print.h" +#include "action.h" + +#define JOYSTIIC_DEFAULT_ADDR 0x20 +#define JOYSTIIC_COMMAND_HORIZONTAL 0x00 +#define JOYSTIIC_COMMAND_VERTICAL 0x02 +#define JOYSTIIC_COMMAND_BUTTON 0x04 + +#define JOYSTIIC_CENTER 512 +#define JOYSTIIC_DEADZONE 200 + +uint16_t joystiic_horizontal; +uint16_t joystiic_vertical; +bool joystiic_button; + +uint8_t joystiic_tx[1]; +uint8_t joystiic_rx_horizontal[2]; +uint8_t joystiic_rx_vertical[2]; +uint8_t joystiic_rx_button[1]; + +enum { + JOYSTIIC_LEFT, + JOYSTIIC_RIGHT, + JOYSTIIC_UP, + JOYSTIIC_DOWN, + JOYSTIIC_PRESS +}; + +bool joystiic_triggered[5] = {0}; + +void joystiic_init(void) { + i2c_init(); + i2c_start(JOYSTIIC_DEFAULT_ADDR); +} + +void joystiic_update(uint16_t horizontal, uint16_t vertical, bool button) { + joystiic_update_kb(horizontal, vertical, button); + joystiic_update_user(horizontal, vertical, button); +} + +void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button) { + +} + +void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button) { + +} + +void joystiic_trigger(uint8_t trigger, bool active) { + joystiic_trigger_kb(trigger, active); + joystiic_trigger_user(trigger, active); +} + +void joystiic_trigger_kb(uint8_t trigger, bool active) { + switch (trigger) { + case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break; + } +} + +void joystiic_trigger_user(uint8_t trigger, bool active) { + +} + +void joystiic_task(void) { + // get horizontal axis + joystiic_tx[0] = JOYSTIIC_COMMAND_HORIZONTAL; + + if (MSG_OK != i2c_transmit_receive(JOYSTIIC_DEFAULT_ADDR << 1, + joystiic_tx, 1, + joystiic_rx_horizontal, 2 + )) { + printf("error hori\n"); + } + + joystiic_horizontal = ((uint16_t)joystiic_rx_horizontal[0] << 8) | joystiic_rx_horizontal[1]; + + if (joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) { + if (!joystiic_triggered[JOYSTIIC_LEFT]) { + joystiic_triggered[JOYSTIIC_LEFT] = true; + joystiic_trigger(JOYSTIIC_LEFT, true); + } + } else { + if (joystiic_triggered[JOYSTIIC_LEFT]) { + joystiic_triggered[JOYSTIIC_LEFT] = false; + joystiic_trigger(JOYSTIIC_LEFT, false); + } + } + + if (joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)) { + if (!joystiic_triggered[JOYSTIIC_RIGHT]) { + joystiic_triggered[JOYSTIIC_RIGHT] = true; + joystiic_trigger(JOYSTIIC_RIGHT, true); + } + } else { + if (joystiic_triggered[JOYSTIIC_RIGHT]) { + joystiic_triggered[JOYSTIIC_RIGHT] = false; + joystiic_trigger(JOYSTIIC_RIGHT, false); + } + } + + // get vertical axis + joystiic_tx[0] = JOYSTIIC_COMMAND_VERTICAL; + if (MSG_OK != i2c_transmit_receive(JOYSTIIC_DEFAULT_ADDR << 1, + joystiic_tx, 1, + joystiic_rx_vertical, 2 + )) { + printf("error vert\n"); + } + + joystiic_vertical = ((uint16_t)joystiic_rx_vertical[0] << 8) | joystiic_rx_vertical[1]; + + if (joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) { + if (!joystiic_triggered[JOYSTIIC_UP]) { + joystiic_triggered[JOYSTIIC_UP] = true; + joystiic_trigger(JOYSTIIC_UP, true); + } + } else { + if (joystiic_triggered[JOYSTIIC_UP]) { + joystiic_triggered[JOYSTIIC_UP] = false; + joystiic_trigger(JOYSTIIC_UP, false); + } + } + + if (joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)) { + if (!joystiic_triggered[JOYSTIIC_DOWN]) { + joystiic_triggered[JOYSTIIC_DOWN] = true; + joystiic_trigger(JOYSTIIC_DOWN, true); + } + } else { + if (joystiic_triggered[JOYSTIIC_DOWN]) { + joystiic_triggered[JOYSTIIC_DOWN] = false; + joystiic_trigger(JOYSTIIC_DOWN, false); + } + } + + // get button press + joystiic_tx[0] = JOYSTIIC_COMMAND_BUTTON; + if (MSG_OK != i2c_transmit_receive(JOYSTIIC_DEFAULT_ADDR << 1, + joystiic_tx, 1, + joystiic_rx_button, 1 + )) { + printf("error vert\n"); + } + + joystiic_button = joystiic_rx_button[0]; + + if (joystiic_button) { + if (!joystiic_triggered[JOYSTIIC_PRESS]) { + joystiic_triggered[JOYSTIIC_PRESS] = true; + joystiic_trigger(JOYSTIIC_PRESS, true); + } + } else { + if (joystiic_triggered[JOYSTIIC_PRESS]) { + joystiic_triggered[JOYSTIIC_PRESS] = false; + joystiic_trigger(JOYSTIIC_PRESS, false); + } + } + + joystiic_update(joystiic_horizontal, joystiic_vertical, joystiic_button); + + //printf("%d\n", joystiic[0]); + + // SEND_STRING("H: "); + // send_word(joystiic_rx_horizontal[0]); + // tap_code(KC_SPACE); + // send_word(joystiic_rx_horizontal[1]); + // tap_code(KC_SPACE); +} diff --git a/drivers/qwiic/joystiic.h b/drivers/qwiic/joystiic.h new file mode 100644 index 0000000000..808f1a626e --- /dev/null +++ b/drivers/qwiic/joystiic.h @@ -0,0 +1,26 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include "i2c_master.h" + +void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button); +void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button); +void joystiic_trigger_kb(uint8_t trigger, bool active); +void joystiic_trigger_user(uint8_t trigger, bool active); + +void joystiic_init(void); +void joystiic_task(void); diff --git a/keyboards/planck/rev6/halconf.h b/keyboards/planck/rev6/halconf.h index 8fe8e0c6f5..c3e0cbb728 100644 --- a/keyboards/planck/rev6/halconf.h +++ b/keyboards/planck/rev6/halconf.h @@ -76,7 +76,7 @@ * @brief Enables the I2C subsystem. */ #if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) -#define HAL_USE_I2C FALSE +#define HAL_USE_I2C TRUE #endif /** diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index 7c3c6e570c..36f8ca2252 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -154,7 +154,7 @@ /* * I2C driver system settings. */ -#define STM32_I2C_USE_I2C1 FALSE +#define STM32_I2C_USE_I2C1 TRUE #define STM32_I2C_USE_I2C2 FALSE #define STM32_I2C_BUSY_TIMEOUT 50 #define STM32_I2C_I2C1_IRQ_PRIORITY 10 diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 650e1a194d..e4b5365f99 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -14,11 +14,14 @@ * along with this program. If not, see . */ #include "rev6.h" +#include "qwiic/joystiic.h" void matrix_init_kb(void) { matrix_init_user(); + joystiic_init(); } void matrix_scan_kb(void) { matrix_scan_user(); + joystiic_task(); } diff --git a/keyboards/planck/rev6/rules.mk b/keyboards/planck/rev6/rules.mk index 3603e287b3..c3e9f23afb 100644 --- a/keyboards/planck/rev6/rules.mk +++ b/keyboards/planck/rev6/rules.mk @@ -1,5 +1,5 @@ # project specific files -SRC = matrix.c +SRC = matrix.c qwiic/joystiic.c i2c_master.c LAYOUTS += ortho_4x12 ## chip/board settings From 636c5989de2bfd428b723d611f1382eff00dece1 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 2 Oct 2018 23:16:03 -0400 Subject: [PATCH 2/6] actually qwiic framework with hooks --- common_features.mk | 2 + drivers/qwiic/joystiic.c | 99 +++++++--------------------------- drivers/qwiic/joystiic.h | 10 +++- drivers/qwiic/qwiic.c | 28 ++++++++++ drivers/qwiic/qwiic.h | 25 +++++++++ drivers/qwiic/qwiic.mk | 13 +++++ keyboards/planck/rev6/rev6.c | 14 +++-- keyboards/planck/rev6/rules.mk | 3 +- tmk_core/common/keyboard.c | 10 ++++ 9 files changed, 120 insertions(+), 84 deletions(-) create mode 100644 drivers/qwiic/qwiic.c create mode 100644 drivers/qwiic/qwiic.h create mode 100644 drivers/qwiic/qwiic.mk diff --git a/common_features.mk b/common_features.mk index 65ff6b5b38..cb36301690 100644 --- a/common_features.mk +++ b/common_features.mk @@ -234,6 +234,8 @@ ifeq ($(strip $(LEADER_ENABLE)), yes) OPT_DEFS += -DLEADER_ENABLE endif +include $(DRIVER_PATH)/qwiic/qwiic.mk + QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ diff --git a/drivers/qwiic/joystiic.c b/drivers/qwiic/joystiic.c index ac97a22cd7..7f4d550573 100644 --- a/drivers/qwiic/joystiic.c +++ b/drivers/qwiic/joystiic.c @@ -34,14 +34,6 @@ uint8_t joystiic_rx_horizontal[2]; uint8_t joystiic_rx_vertical[2]; uint8_t joystiic_rx_button[1]; -enum { - JOYSTIIC_LEFT, - JOYSTIIC_RIGHT, - JOYSTIIC_UP, - JOYSTIIC_DOWN, - JOYSTIIC_PRESS -}; - bool joystiic_triggered[5] = {0}; void joystiic_init(void) { @@ -54,29 +46,30 @@ void joystiic_update(uint16_t horizontal, uint16_t vertical, bool button) { joystiic_update_user(horizontal, vertical, button); } -void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button) { +__attribute__ ((weak)) +void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button) { } -} - -void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button) { - -} +__attribute__ ((weak)) +void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button) { } void joystiic_trigger(uint8_t trigger, bool active) { joystiic_trigger_kb(trigger, active); joystiic_trigger_user(trigger, active); } -void joystiic_trigger_kb(uint8_t trigger, bool active) { - switch (trigger) { - case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break; +__attribute__ ((weak)) +void joystiic_trigger_kb(uint8_t trigger, bool active) { } + +__attribute__ ((weak)) +void joystiic_trigger_user(uint8_t trigger, bool active) { } + +void joystiic_trigger_if_not(uint8_t trigger, bool active) { + if (joystiic_triggered[trigger] != active) { + joystiic_triggered[trigger] = active; + joystiic_trigger(trigger, active); } } -void joystiic_trigger_user(uint8_t trigger, bool active) { - -} - void joystiic_task(void) { // get horizontal axis joystiic_tx[0] = JOYSTIIC_COMMAND_HORIZONTAL; @@ -90,29 +83,8 @@ void joystiic_task(void) { joystiic_horizontal = ((uint16_t)joystiic_rx_horizontal[0] << 8) | joystiic_rx_horizontal[1]; - if (joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) { - if (!joystiic_triggered[JOYSTIIC_LEFT]) { - joystiic_triggered[JOYSTIIC_LEFT] = true; - joystiic_trigger(JOYSTIIC_LEFT, true); - } - } else { - if (joystiic_triggered[JOYSTIIC_LEFT]) { - joystiic_triggered[JOYSTIIC_LEFT] = false; - joystiic_trigger(JOYSTIIC_LEFT, false); - } - } - - if (joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)) { - if (!joystiic_triggered[JOYSTIIC_RIGHT]) { - joystiic_triggered[JOYSTIIC_RIGHT] = true; - joystiic_trigger(JOYSTIIC_RIGHT, true); - } - } else { - if (joystiic_triggered[JOYSTIIC_RIGHT]) { - joystiic_triggered[JOYSTIIC_RIGHT] = false; - joystiic_trigger(JOYSTIIC_RIGHT, false); - } - } + joystiic_trigger_if_not(JOYSTIIC_LEFT, joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)); + joystiic_trigger_if_not(JOYSTIIC_RIGHT, joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)); // get vertical axis joystiic_tx[0] = JOYSTIIC_COMMAND_VERTICAL; @@ -125,29 +97,8 @@ void joystiic_task(void) { joystiic_vertical = ((uint16_t)joystiic_rx_vertical[0] << 8) | joystiic_rx_vertical[1]; - if (joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) { - if (!joystiic_triggered[JOYSTIIC_UP]) { - joystiic_triggered[JOYSTIIC_UP] = true; - joystiic_trigger(JOYSTIIC_UP, true); - } - } else { - if (joystiic_triggered[JOYSTIIC_UP]) { - joystiic_triggered[JOYSTIIC_UP] = false; - joystiic_trigger(JOYSTIIC_UP, false); - } - } - - if (joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)) { - if (!joystiic_triggered[JOYSTIIC_DOWN]) { - joystiic_triggered[JOYSTIIC_DOWN] = true; - joystiic_trigger(JOYSTIIC_DOWN, true); - } - } else { - if (joystiic_triggered[JOYSTIIC_DOWN]) { - joystiic_triggered[JOYSTIIC_DOWN] = false; - joystiic_trigger(JOYSTIIC_DOWN, false); - } - } + joystiic_trigger_if_not(JOYSTIIC_UP, joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)); + joystiic_trigger_if_not(JOYSTIIC_DOWN, joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)); // get button press joystiic_tx[0] = JOYSTIIC_COMMAND_BUTTON; @@ -158,19 +109,9 @@ void joystiic_task(void) { printf("error vert\n"); } - joystiic_button = joystiic_rx_button[0]; + joystiic_button = !joystiic_rx_button[0]; - if (joystiic_button) { - if (!joystiic_triggered[JOYSTIIC_PRESS]) { - joystiic_triggered[JOYSTIIC_PRESS] = true; - joystiic_trigger(JOYSTIIC_PRESS, true); - } - } else { - if (joystiic_triggered[JOYSTIIC_PRESS]) { - joystiic_triggered[JOYSTIIC_PRESS] = false; - joystiic_trigger(JOYSTIIC_PRESS, false); - } - } + joystiic_trigger_if_not(JOYSTIIC_PRESS, joystiic_button); joystiic_update(joystiic_horizontal, joystiic_vertical, joystiic_button); diff --git a/drivers/qwiic/joystiic.h b/drivers/qwiic/joystiic.h index 808f1a626e..bb470864c6 100644 --- a/drivers/qwiic/joystiic.h +++ b/drivers/qwiic/joystiic.h @@ -15,7 +15,15 @@ */ #pragma once -#include "i2c_master.h" +#include "qwiic.h" + +enum { + JOYSTIIC_LEFT, + JOYSTIIC_RIGHT, + JOYSTIIC_UP, + JOYSTIIC_DOWN, + JOYSTIIC_PRESS +}; void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button); void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button); diff --git a/drivers/qwiic/qwiic.c b/drivers/qwiic/qwiic.c new file mode 100644 index 0000000000..d69f834c66 --- /dev/null +++ b/drivers/qwiic/qwiic.c @@ -0,0 +1,28 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "qwiic.h" + +void qwiic_init(void) { + #ifdef QWIIC_JOYSTIIC_ENABLE + joystiic_init(); + #endif +} + +void qwiic_task(void) { + #ifdef QWIIC_JOYSTIIC_ENABLE + joystiic_task(); + #endif +} diff --git a/drivers/qwiic/qwiic.h b/drivers/qwiic/qwiic.h new file mode 100644 index 0000000000..1a931d3f07 --- /dev/null +++ b/drivers/qwiic/qwiic.h @@ -0,0 +1,25 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include "i2c_master.h" + +#ifdef QWIIC_JOYSTIIC_ENABLE + #include "joystiic.h" +#endif + +void qwiic_init(void); +void qwiic_task(void); diff --git a/drivers/qwiic/qwiic.mk b/drivers/qwiic/qwiic.mk new file mode 100644 index 0000000000..4145540dc7 --- /dev/null +++ b/drivers/qwiic/qwiic.mk @@ -0,0 +1,13 @@ +ifneq ($(strip $(QWIIC_ENABLE)),) + COMMON_VPATH += $(DRIVER_PATH)/qwiic + OPT_DEFS += -DQWIIC_ENABLE + SRC += qwiic.c + ifeq ($(filter "i2c_master.c", $(SRC)),) + SRC += i2c_master.c + endif +endif + +ifneq ($(filter JOYSTIIC, $(QWIIC_ENABLE)),) + OPT_DEFS += -DQWIIC_JOYSTIIC_ENABLE + SRC += joystiic.c +endif diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index e4b5365f99..41cc06a436 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -14,14 +14,22 @@ * along with this program. If not, see . */ #include "rev6.h" -#include "qwiic/joystiic.h" +#include "qwiic.h" void matrix_init_kb(void) { matrix_init_user(); - joystiic_init(); } void matrix_scan_kb(void) { matrix_scan_user(); - joystiic_task(); +} + +void joystiic_trigger_kb(uint8_t trigger, bool active) { + switch (trigger) { + case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break; + case JOYSTIIC_RIGHT: active ? register_code(KC_R) : unregister_code(KC_R); break; + case JOYSTIIC_UP: active ? register_code(KC_U) : unregister_code(KC_U); break; + case JOYSTIIC_DOWN: active ? register_code(KC_D) : unregister_code(KC_D); break; + case JOYSTIIC_PRESS: active ? register_code(KC_P) : unregister_code(KC_P); break; + } } diff --git a/keyboards/planck/rev6/rules.mk b/keyboards/planck/rev6/rules.mk index c3e9f23afb..0ee32f2ce9 100644 --- a/keyboards/planck/rev6/rules.mk +++ b/keyboards/planck/rev6/rules.mk @@ -1,5 +1,5 @@ # project specific files -SRC = matrix.c qwiic/joystiic.c i2c_master.c +SRC = matrix.c LAYOUTS += ortho_4x12 ## chip/board settings @@ -53,4 +53,5 @@ NKRO_ENABLE = yes # USB Nkey Rollover CUSTOM_MATRIX = yes # Custom matrix file AUDIO_ENABLE = yes RGBLIGHT_ENABLE = no +QWIIC_ENABLE += JOYSTIIC # SERIAL_LINK_ENABLE = yes diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 13b3cb4c0c..9b8689694d 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -72,6 +72,9 @@ along with this program. If not, see . #ifdef HD44780_ENABLE # include "hd44780.h" #endif +#ifdef QWIIC_ENABLE +# include "qwiic.h" +#endif #ifdef MATRIX_HAS_GHOST extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; @@ -157,6 +160,9 @@ void keyboard_init(void) { MCUCR |= _BV(JTD); #endif matrix_init(); +#ifdef QWIIC_ENABLE + qwiic_init(); +#endif #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif @@ -266,6 +272,10 @@ void keyboard_task(void) MATRIX_LOOP_END: +#ifdef QWIIC_ENABLE + qwiic_task(); +#endif + #ifdef MOUSEKEY_ENABLE // mousekey repeat & acceleration mousekey_task(); From a094696548382f3f77faa585ebcaf6e17d202f2a Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 2 Oct 2018 23:20:02 -0400 Subject: [PATCH 3/6] add readme for qwiic stuff --- drivers/qwiic/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 drivers/qwiic/readme.md diff --git a/drivers/qwiic/readme.md b/drivers/qwiic/readme.md new file mode 100644 index 0000000000..db88f6b78a --- /dev/null +++ b/drivers/qwiic/readme.md @@ -0,0 +1,7 @@ +# Qwiic Devices + +[More info on Sparkfun's Qwiic Connect System](https://www.sparkfun.com/qwiic) + +Currently supported devices: + +* [Joystiic](https://www.sparkfun.com/products/14656) From 129df28574ca9b2f328a871d59eede337bce4079 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 11 Oct 2018 02:07:09 -0400 Subject: [PATCH 4/6] adds support for the micro oled display --- drivers/qwiic/micro_oled.c | 457 +++++++++++++++++++++++++++++++++ drivers/qwiic/micro_oled.h | 128 +++++++++ drivers/qwiic/qwiic.c | 3 + drivers/qwiic/qwiic.h | 3 + drivers/qwiic/qwiic.mk | 5 + drivers/qwiic/util/font5x7.h | 288 +++++++++++++++++++++ drivers/qwiic/util/font8x16.h | 127 +++++++++ keyboards/planck/rev6/rev6.c | 76 ++++++ keyboards/planck/rev6/rules.mk | 2 +- tmk_core/common/action_layer.h | 8 +- 10 files changed, 1091 insertions(+), 6 deletions(-) create mode 100644 drivers/qwiic/micro_oled.c create mode 100644 drivers/qwiic/micro_oled.h create mode 100644 drivers/qwiic/util/font5x7.h create mode 100644 drivers/qwiic/util/font8x16.h diff --git a/drivers/qwiic/micro_oled.c b/drivers/qwiic/micro_oled.c new file mode 100644 index 0000000000..46765f389c --- /dev/null +++ b/drivers/qwiic/micro_oled.c @@ -0,0 +1,457 @@ +/* Jim Lindblom @ SparkFun Electronics + * October 26, 2014 + * https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED + * + * Modified by: + * Emil Varughese @ Edwin Robotics Pvt. Ltd. + * July 27, 2015 + * https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/ + * + * This code was heavily based around the MicroView library, written by GeekAmmo + * (https://github.com/geekammo/MicroView-Arduino-Library). + * + * Adapted for QMK by: + * Jack Humbert + * October 11, 2018 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "micro_oled.h" +#include +#include "util/font5x7.h" +#include "util/font8x16.h" +#include "string.h" + +#define TOTALFONTS 2 +const unsigned char * fonts_pointer[]= { font5x7, font8x16 }; + +uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY; +uint16_t fontMapWidth; + +#define _BV(x) (1 << (x)) +#define swap(a, b) { uint8_t t = a; a = b; b = t; } + +uint8_t micro_oled_transfer_buffer[20]; +static uint8_t micro_oled_screen_buffer[] = { +/* LCD Memory organised in 64 horizontal pixel and 6 rows of byte + B B .............B ----- + y y .............y \ + t t .............t \ + e e .............e \ + 0 1 .............63 \ + \ + D0 D0.............D0 \ + D1 D1.............D1 / ROW 0 + D2 D2.............D2 / + D3 D3.............D3 / + D4 D4.............D4 / + D5 D5.............D5 / + D6 D6.............D6 / + D7 D7.............D7 ---- + */ + +// QMK Logo - generated at http://www.majer.ch/lcd/adf_bitmap.php + +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, +0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, +0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, +0xF8, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFE, +0xFE, 0xF8, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x8C, 0x8C, 0x8C, 0x8C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, +0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x8C, 0x8C, 0x8C, 0x8C, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x31, 0x31, 0x31, 0x31, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF1, 0xE3, 0xE7, 0xCF, +0xCF, 0xCF, 0xCF, 0x00, 0x00, 0xCF, 0xCF, 0xCF, 0xC7, 0xE7, +0xE3, 0xF1, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0x31, 0x31, 0x31, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, +0x06, 0x06, 0x1F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0x7F, 0x7F, 0x1F, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, +0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, +0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00 +}; + +void micro_oled_init(void) { + + i2c_init(); + i2c_start(I2C_ADDRESS_SA0_1); + + // Display Init sequence for 64x48 OLED module + send_command(DISPLAYOFF); // 0xAE + + send_command(SETDISPLAYCLOCKDIV); // 0xD5 + send_command(0x80); // the suggested ratio 0x80 + + send_command(SETMULTIPLEX); // 0xA8 + send_command(0x2F); + + send_command(SETDISPLAYOFFSET); // 0xD3 + send_command(0x0); // no offset + + send_command(SETSTARTLINE | 0x0); // line #0 + + send_command(CHARGEPUMP); // enable charge pump + send_command(0x14); + + send_command(NORMALDISPLAY); // 0xA6 + send_command(DISPLAYALLONRESUME); // 0xA4 + + send_command(SEGREMAP | 0x1); + send_command(COMSCANDEC); + + send_command(SETCOMPINS); // 0xDA + send_command(0x12); + + send_command(SETCONTRAST); // 0x81 + send_command(0x8F); + + send_command(SETPRECHARGE); // 0xd9 + send_command(0xF1); + + send_command(SETVCOMDESELECT); // 0xDB + send_command(0x40); + + send_command(DISPLAYON); //--turn on oled panel + //clear_screen(); // Erase hardware memory inside the OLED controller to avoid random data in memory. + send_buffer(); +} + +void send_command(uint8_t command) { + micro_oled_transfer_buffer[0] = I2C_COMMAND; + micro_oled_transfer_buffer[1] = command; + i2c_transmit(I2C_ADDRESS_SA0_1 << 1, micro_oled_transfer_buffer, 2, 100); +} + +void send_data(uint8_t data) { + micro_oled_transfer_buffer[0] = I2C_DATA; + micro_oled_transfer_buffer[1] = data; + i2c_transmit(I2C_ADDRESS_SA0_1 << 1, micro_oled_transfer_buffer, 2, 100); +} + +/** \brief Set SSD1306 page address. + Send page address command and address to the SSD1306 OLED controller. +*/ +void set_page_address(uint8_t address) { + address = (0xB0 | address); + send_command(address); +} + +/** \brief Set SSD1306 column address. + Send column address command and address to the SSD1306 OLED controller. +*/ +void set_column_address(uint8_t address) { + send_command( ( 0x10 | (address >> 4) ) + 0x02 ); + send_command( 0x0f & address ); +} + +/** \brief Clear SSD1306's memory. + To clear GDRAM inside the LCD controller. +*/ +void clear_screen(void) { + for (int i=0;i<8; i++) { + set_page_address(i); + set_column_address(0); + for (int j=0; j<0x80; j++) { + send_data(0); + } + } +} + +/** \brief Clear SSD1306's memory. + To clear GDRAM inside the LCD controller. +*/ +void clear_buffer(void) { + memset(micro_oled_screen_buffer, 0, 384); +} + +/** \brief Invert display. + The PIXEL_ON color of the display will turn to PIXEL_OFF and the PIXEL_OFF will turn to PIXEL_ON. +*/ +void invert_screen(bool invert) { + if (invert) { + send_command(INVERTDISPLAY); + } else { + send_command(NORMALDISPLAY); + } +} + +/** \brief Set contrast. + OLED contract value from 0 to 255. Note: Contrast level is not very obvious. +*/ +void set_contrast(uint8_t contrast) { + send_command(SETCONTRAST); // 0x81 + send_command(contrast); +} + +/** \brief Transfer display buffer. + Bulk move the screen buffer to the SSD1306 controller's memory so that images/graphics drawn on the screen buffer will be displayed on the OLED. +*/ +void send_buffer(void) { + uint8_t i, j; + + for (i=0; i<6; i++) { + set_page_address(i); + set_column_address(0); + for (j=0;j<0x40;j++) { + send_data(micro_oled_screen_buffer[i*0x40+j]); + } + } +} +/** \brief Draw pixel with color and mode. + Draw color pixel in the screen buffer's x,y position with NORM or XOR draw mode. +*/ +void draw_pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) { + if ((x<0) || (x>=LCDWIDTH) || (y<0) || (y>=LCDHEIGHT)) + return; + + if (mode == XOR) { + if (color == PIXEL_ON) + micro_oled_screen_buffer[x + (y/8)*LCDWIDTH] ^= _BV((y%8)); + } else { + if (color == PIXEL_ON) + micro_oled_screen_buffer[x + (y/8)*LCDWIDTH] |= _BV((y%8)); + else + micro_oled_screen_buffer[x + (y/8)*LCDWIDTH] &= ~_BV((y%8)); + } +} + +/** \brief Draw line with color and mode. +Draw line using color and mode from x0,y0 to x1,y1 of the screen buffer. +*/ +void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) { + uint8_t steep = abs(y1 - y0) > abs(x1 - x0); + if (steep) { + swap(x0, y0); + swap(x1, y1); + } + + if (x0 > x1) { + swap(x0, x1); + swap(y0, y1); + } + + uint8_t dx, dy; + dx = x1 - x0; + dy = abs(y1 - y0); + + int8_t err = dx / 2; + int8_t ystep; + + if (y0 < y1) { + ystep = 1; + } else { + ystep = -1;} + + for (; x0=TOTALFONTS) || (font<0)) + return; + + uint8_t fontType = font; + uint8_t fontWidth = pgm_read_byte(fonts_pointer[fontType]+0); + uint8_t fontHeight = pgm_read_byte(fonts_pointer[fontType]+1); + uint8_t fontStartChar = pgm_read_byte(fonts_pointer[fontType]+2); + uint8_t fontTotalChar = pgm_read_byte(fonts_pointer[fontType]+3); + uint16_t fontMapWidth = (pgm_read_byte(fonts_pointer[fontType]+4)*100)+pgm_read_byte(fonts_pointer[fontType]+5); // two bytes values into integer 16 + + if ((c(fontStartChar+fontTotalChar-1))) // no bitmap for the required c + return; + + tempC=c-fontStartChar; + + // each row (in datasheet is call page) is 8 bits high, 16 bit high character will have 2 rows to be drawn + rowsToDraw=fontHeight/8; // 8 is LCD's page size, see SSD1306 datasheet + if (rowsToDraw<=1) rowsToDraw=1; + + // the following draw function can draw anywhere on the screen, but SLOW pixel by pixel draw + if (rowsToDraw==1) { + for (i=0;i>=1; + } + } + return; + } + + // font height over 8 bit + // take character "0" ASCII 48 as example + charPerBitmapRow = fontMapWidth/fontWidth; // 256/8 =32 char per row + charColPositionOnBitmap = tempC % charPerBitmapRow; // =16 + charRowPositionOnBitmap = (int)(tempC/charPerBitmapRow); // =1 + charBitmapStartPosition = (charRowPositionOnBitmap * fontMapWidth * (fontHeight/8)) + (charColPositionOnBitmap * fontWidth) ; + + // each row on LCD is 8 bit height (see datasheet for explanation) + for(row=0;row>=1; + } + } + } + +} + +void draw_string(uint8_t x, uint8_t y, char * string, uint8_t color, uint8_t mode, uint8_t font) { + + if ((font>=TOTALFONTS) || (font<0)) + return; + + uint8_t fontType = font; + uint8_t fontWidth = pgm_read_byte(fonts_pointer[fontType]+0); + + uint8_t cur_x = x; + for (int i = 0; i < strlen(string); i++) { + draw_char(cur_x, y, string[i], color, mode, font); + cur_x += fontWidth + 1; + } + +} diff --git a/drivers/qwiic/micro_oled.h b/drivers/qwiic/micro_oled.h new file mode 100644 index 0000000000..faa06313d1 --- /dev/null +++ b/drivers/qwiic/micro_oled.h @@ -0,0 +1,128 @@ +/* Jim Lindblom @ SparkFun Electronics + * October 26, 2014 + * https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED + * + * Modified by: + * Emil Varughese @ Edwin Robotics Pvt. Ltd. + * July 27, 2015 + * https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/ + * + * This code was heavily based around the MicroView library, written by GeekAmmo + * (https://github.com/geekammo/MicroView-Arduino-Library). + * + * Adapted for QMK by: + * Jack Humbert + * October 11, 2018 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include "qwiic.h" + +void micro_oled_init(void); + +void send_command(uint8_t command); +void send_data(uint8_t data); +void set_page_address(uint8_t address); +void set_column_address(uint8_t address); +void clear_buffer(void); +void send_buffer(void); +void draw_pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode); +void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode); +void draw_line_hori(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode); +void draw_line_vert(uint8_t x, uint8_t y, uint8_t height, bool color, uint8_t mode); +void draw_rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode); +void draw_rect_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode); +void draw_rect_filled(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode); +void draw_rect_filled_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode); +void draw_char(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode, uint8_t font); +void draw_string(uint8_t x, uint8_t y, char * string, uint8_t color, uint8_t mode, uint8_t font); + +#define I2C_ADDRESS_SA0_0 0b0111100 +#define I2C_ADDRESS_SA0_1 0b0111101 +#define I2C_COMMAND 0x00 +#define I2C_DATA 0x40 + +#define PIXEL_OFF 0 +#define PIXEL_ON 1 + +#define LCDWIDTH 64 +#define LCDHEIGHT 48 +#define FONTHEADERSIZE 6 + +#define NORM 0 +#define XOR 1 + +#define PAGE 0 +#define ALL 1 + +#define WIDGETSTYLE0 0 +#define WIDGETSTYLE1 1 +#define WIDGETSTYLE2 2 + +#define SETCONTRAST 0x81 +#define DISPLAYALLONRESUME 0xA4 +#define DISPLAYALLON 0xA5 +#define NORMALDISPLAY 0xA6 +#define INVERTDISPLAY 0xA7 +#define DISPLAYOFF 0xAE +#define DISPLAYON 0xAF +#define SETDISPLAYOFFSET 0xD3 +#define SETCOMPINS 0xDA +#define SETVCOMDESELECT 0xDB +#define SETDISPLAYCLOCKDIV 0xD5 +#define SETPRECHARGE 0xD9 +#define SETMULTIPLEX 0xA8 +#define SETLOWCOLUMN 0x00 +#define SETHIGHCOLUMN 0x10 +#define SETSTARTLINE 0x40 +#define MEMORYMODE 0x20 +#define COMSCANINC 0xC0 +#define COMSCANDEC 0xC8 +#define SEGREMAP 0xA0 +#define CHARGEPUMP 0x8D +#define EXTERNALVCC 0x01 +#define SWITCHCAPVCC 0x02 + +// Scroll +#define ACTIVATESCROLL 0x2F +#define DEACTIVATESCROLL 0x2E +#define SETVERTICALSCROLLAREA 0xA3 +#define RIGHTHORIZONTALSCROLL 0x26 +#define LEFT_HORIZONTALSCROLL 0x27 +#define VERTICALRIGHTHORIZONTALSCROLL 0x29 +#define VERTICALLEFTHORIZONTALSCROLL 0x2A + +typedef enum CMD { + CMD_CLEAR, //0 + CMD_INVERT, //1 + CMD_CONTRAST, //2 + CMD_DISPLAY, //3 + CMD_SETCURSOR, //4 + CMD_PIXEL, //5 + CMD_LINE, //6 + CMD_LINEH, //7 + CMD_LINEV, //8 + CMD_RECT, //9 + CMD_RECTFILL, //10 + CMD_CIRCLE, //11 + CMD_CIRCLEFILL, //12 + CMD_DRAWCHAR, //13 + CMD_DRAWBITMAP, //14 + CMD_GETLCDWIDTH, //15 + CMD_GETLCDHEIGHT, //16 + CMD_SETCOLOR, //17 + CMD_SETDRAWMODE //18 +} commCommand_t; diff --git a/drivers/qwiic/qwiic.c b/drivers/qwiic/qwiic.c index d69f834c66..9047919927 100644 --- a/drivers/qwiic/qwiic.c +++ b/drivers/qwiic/qwiic.c @@ -19,6 +19,9 @@ void qwiic_init(void) { #ifdef QWIIC_JOYSTIIC_ENABLE joystiic_init(); #endif + #ifdef QWIIC_MICRO_OLED_ENABLE + micro_oled_init(); + #endif } void qwiic_task(void) { diff --git a/drivers/qwiic/qwiic.h b/drivers/qwiic/qwiic.h index 1a931d3f07..160fb28dfd 100644 --- a/drivers/qwiic/qwiic.h +++ b/drivers/qwiic/qwiic.h @@ -20,6 +20,9 @@ #ifdef QWIIC_JOYSTIIC_ENABLE #include "joystiic.h" #endif +#ifdef QWIIC_MICRO_OLED_ENABLE + #include "micro_oled.h" +#endif void qwiic_init(void); void qwiic_task(void); diff --git a/drivers/qwiic/qwiic.mk b/drivers/qwiic/qwiic.mk index 4145540dc7..4ae2d78e3e 100644 --- a/drivers/qwiic/qwiic.mk +++ b/drivers/qwiic/qwiic.mk @@ -11,3 +11,8 @@ ifneq ($(filter JOYSTIIC, $(QWIIC_ENABLE)),) OPT_DEFS += -DQWIIC_JOYSTIIC_ENABLE SRC += joystiic.c endif + +ifneq ($(filter MICRO_OLED, $(QWIIC_ENABLE)),) + OPT_DEFS += -DQWIIC_MICRO_OLED_ENABLE + SRC += micro_oled.c +endif diff --git a/drivers/qwiic/util/font5x7.h b/drivers/qwiic/util/font5x7.h new file mode 100644 index 0000000000..0bad206b7c --- /dev/null +++ b/drivers/qwiic/util/font5x7.h @@ -0,0 +1,288 @@ +/****************************************************************************** +font5x7.h +Definition for small font + +This file was imported from the MicroView library, written by GeekAmmo +(https://github.com/geekammo/MicroView-Arduino-Library), and released under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Modified by: +Emil Varughese @ Edwin Robotics Pvt. Ltd. +July 27, 2015 +https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/ + +******************************************************************************/ +#pragma once + +#include "progmem.h" + +// Standard ASCII 5x7 font +static const unsigned char font5x7[] PROGMEM = { + // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) + 5,8,0,255,12,75, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, + 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, + 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, + 0x18, 0x3C, 0x7E, 0x3C, 0x18, + 0x1C, 0x57, 0x7D, 0x57, 0x1C, + 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, + 0x00, 0x18, 0x3C, 0x18, 0x00, + 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, + 0x00, 0x18, 0x24, 0x18, 0x00, + 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, + 0x30, 0x48, 0x3A, 0x06, 0x0E, + 0x26, 0x29, 0x79, 0x29, 0x26, + 0x40, 0x7F, 0x05, 0x05, 0x07, + 0x40, 0x7F, 0x05, 0x25, 0x3F, + 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, + 0x7F, 0x3E, 0x1C, 0x1C, 0x08, + 0x08, 0x1C, 0x1C, 0x3E, 0x7F, + 0x14, 0x22, 0x7F, 0x22, 0x14, + 0x5F, 0x5F, 0x00, 0x5F, 0x5F, + 0x06, 0x09, 0x7F, 0x01, 0x7F, + 0x00, 0x66, 0x89, 0x95, 0x6A, + 0x60, 0x60, 0x60, 0x60, 0x60, + 0x94, 0xA2, 0xFF, 0xA2, 0x94, + 0x08, 0x04, 0x7E, 0x04, 0x08, + 0x10, 0x20, 0x7E, 0x20, 0x10, + 0x08, 0x08, 0x2A, 0x1C, 0x08, + 0x08, 0x1C, 0x2A, 0x08, 0x08, + 0x1E, 0x10, 0x10, 0x10, 0x10, + 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, + 0x30, 0x38, 0x3E, 0x38, 0x30, + 0x06, 0x0E, 0x3E, 0x0E, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x5F, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x07, 0x00, + 0x14, 0x7F, 0x14, 0x7F, 0x14, + 0x24, 0x2A, 0x7F, 0x2A, 0x12, + 0x23, 0x13, 0x08, 0x64, 0x62, + 0x36, 0x49, 0x56, 0x20, 0x50, + 0x00, 0x08, 0x07, 0x03, 0x00, + 0x00, 0x1C, 0x22, 0x41, 0x00, + 0x00, 0x41, 0x22, 0x1C, 0x00, + 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, + 0x08, 0x08, 0x3E, 0x08, 0x08, + 0x00, 0x80, 0x70, 0x30, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x60, 0x60, 0x00, + 0x20, 0x10, 0x08, 0x04, 0x02, + 0x3E, 0x51, 0x49, 0x45, 0x3E, + 0x00, 0x42, 0x7F, 0x40, 0x00, + 0x72, 0x49, 0x49, 0x49, 0x46, + 0x21, 0x41, 0x49, 0x4D, 0x33, + 0x18, 0x14, 0x12, 0x7F, 0x10, + 0x27, 0x45, 0x45, 0x45, 0x39, + 0x3C, 0x4A, 0x49, 0x49, 0x31, + 0x41, 0x21, 0x11, 0x09, 0x07, + 0x36, 0x49, 0x49, 0x49, 0x36, + 0x46, 0x49, 0x49, 0x29, 0x1E, + 0x00, 0x00, 0x14, 0x00, 0x00, + 0x00, 0x40, 0x34, 0x00, 0x00, + 0x00, 0x08, 0x14, 0x22, 0x41, + 0x14, 0x14, 0x14, 0x14, 0x14, + 0x00, 0x41, 0x22, 0x14, 0x08, + 0x02, 0x01, 0x59, 0x09, 0x06, + 0x3E, 0x41, 0x5D, 0x59, 0x4E, + 0x7C, 0x12, 0x11, 0x12, 0x7C, + 0x7F, 0x49, 0x49, 0x49, 0x36, + 0x3E, 0x41, 0x41, 0x41, 0x22, + 0x7F, 0x41, 0x41, 0x41, 0x3E, + 0x7F, 0x49, 0x49, 0x49, 0x41, + 0x7F, 0x09, 0x09, 0x09, 0x01, + 0x3E, 0x41, 0x41, 0x51, 0x73, + 0x7F, 0x08, 0x08, 0x08, 0x7F, + 0x00, 0x41, 0x7F, 0x41, 0x00, + 0x20, 0x40, 0x41, 0x3F, 0x01, + 0x7F, 0x08, 0x14, 0x22, 0x41, + 0x7F, 0x40, 0x40, 0x40, 0x40, + 0x7F, 0x02, 0x1C, 0x02, 0x7F, + 0x7F, 0x04, 0x08, 0x10, 0x7F, + 0x3E, 0x41, 0x41, 0x41, 0x3E, + 0x7F, 0x09, 0x09, 0x09, 0x06, + 0x3E, 0x41, 0x51, 0x21, 0x5E, + 0x7F, 0x09, 0x19, 0x29, 0x46, + 0x26, 0x49, 0x49, 0x49, 0x32, + 0x03, 0x01, 0x7F, 0x01, 0x03, + 0x3F, 0x40, 0x40, 0x40, 0x3F, + 0x1F, 0x20, 0x40, 0x20, 0x1F, + 0x3F, 0x40, 0x38, 0x40, 0x3F, + 0x63, 0x14, 0x08, 0x14, 0x63, + 0x03, 0x04, 0x78, 0x04, 0x03, + 0x61, 0x59, 0x49, 0x4D, 0x43, + 0x00, 0x7F, 0x41, 0x41, 0x41, + 0x02, 0x04, 0x08, 0x10, 0x20, + 0x00, 0x41, 0x41, 0x41, 0x7F, + 0x04, 0x02, 0x01, 0x02, 0x04, + 0x40, 0x40, 0x40, 0x40, 0x40, + 0x00, 0x03, 0x07, 0x08, 0x00, + 0x20, 0x54, 0x54, 0x78, 0x40, + 0x7F, 0x28, 0x44, 0x44, 0x38, + 0x38, 0x44, 0x44, 0x44, 0x28, + 0x38, 0x44, 0x44, 0x28, 0x7F, + 0x38, 0x54, 0x54, 0x54, 0x18, + 0x00, 0x08, 0x7E, 0x09, 0x02, + 0x18, 0xA4, 0xA4, 0x9C, 0x78, + 0x7F, 0x08, 0x04, 0x04, 0x78, + 0x00, 0x44, 0x7D, 0x40, 0x00, + 0x20, 0x40, 0x40, 0x3D, 0x00, + 0x7F, 0x10, 0x28, 0x44, 0x00, + 0x00, 0x41, 0x7F, 0x40, 0x00, + 0x7C, 0x04, 0x78, 0x04, 0x78, + 0x7C, 0x08, 0x04, 0x04, 0x78, + 0x38, 0x44, 0x44, 0x44, 0x38, + 0xFC, 0x18, 0x24, 0x24, 0x18, + 0x18, 0x24, 0x24, 0x18, 0xFC, + 0x7C, 0x08, 0x04, 0x04, 0x08, + 0x48, 0x54, 0x54, 0x54, 0x24, + 0x04, 0x04, 0x3F, 0x44, 0x24, + 0x3C, 0x40, 0x40, 0x20, 0x7C, + 0x1C, 0x20, 0x40, 0x20, 0x1C, + 0x3C, 0x40, 0x30, 0x40, 0x3C, + 0x44, 0x28, 0x10, 0x28, 0x44, + 0x4C, 0x90, 0x90, 0x90, 0x7C, + 0x44, 0x64, 0x54, 0x4C, 0x44, + 0x00, 0x08, 0x36, 0x41, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, + 0x00, 0x41, 0x36, 0x08, 0x00, + 0x02, 0x01, 0x02, 0x04, 0x02, + 0x3C, 0x26, 0x23, 0x26, 0x3C, + 0x1E, 0xA1, 0xA1, 0x61, 0x12, + 0x3A, 0x40, 0x40, 0x20, 0x7A, + 0x38, 0x54, 0x54, 0x55, 0x59, + 0x21, 0x55, 0x55, 0x79, 0x41, + 0x21, 0x54, 0x54, 0x78, 0x41, + 0x21, 0x55, 0x54, 0x78, 0x40, + 0x20, 0x54, 0x55, 0x79, 0x40, + 0x0C, 0x1E, 0x52, 0x72, 0x12, + 0x39, 0x55, 0x55, 0x55, 0x59, + 0x39, 0x54, 0x54, 0x54, 0x59, + 0x39, 0x55, 0x54, 0x54, 0x58, + 0x00, 0x00, 0x45, 0x7C, 0x41, + 0x00, 0x02, 0x45, 0x7D, 0x42, + 0x00, 0x01, 0x45, 0x7C, 0x40, + 0xF0, 0x29, 0x24, 0x29, 0xF0, + 0xF0, 0x28, 0x25, 0x28, 0xF0, + 0x7C, 0x54, 0x55, 0x45, 0x00, + 0x20, 0x54, 0x54, 0x7C, 0x54, + 0x7C, 0x0A, 0x09, 0x7F, 0x49, + 0x32, 0x49, 0x49, 0x49, 0x32, + 0x32, 0x48, 0x48, 0x48, 0x32, + 0x32, 0x4A, 0x48, 0x48, 0x30, + 0x3A, 0x41, 0x41, 0x21, 0x7A, + 0x3A, 0x42, 0x40, 0x20, 0x78, + 0x00, 0x9D, 0xA0, 0xA0, 0x7D, + 0x39, 0x44, 0x44, 0x44, 0x39, + 0x3D, 0x40, 0x40, 0x40, 0x3D, + 0x3C, 0x24, 0xFF, 0x24, 0x24, + 0x48, 0x7E, 0x49, 0x43, 0x66, + 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, + 0xFF, 0x09, 0x29, 0xF6, 0x20, + 0xC0, 0x88, 0x7E, 0x09, 0x03, + 0x20, 0x54, 0x54, 0x79, 0x41, + 0x00, 0x00, 0x44, 0x7D, 0x41, + 0x30, 0x48, 0x48, 0x4A, 0x32, + 0x38, 0x40, 0x40, 0x22, 0x7A, + 0x00, 0x7A, 0x0A, 0x0A, 0x72, + 0x7D, 0x0D, 0x19, 0x31, 0x7D, + 0x26, 0x29, 0x29, 0x2F, 0x28, + 0x26, 0x29, 0x29, 0x29, 0x26, + 0x30, 0x48, 0x4D, 0x40, 0x20, + 0x38, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x38, + 0x2F, 0x10, 0xC8, 0xAC, 0xBA, + 0x2F, 0x10, 0x28, 0x34, 0xFA, + 0x00, 0x00, 0x7B, 0x00, 0x00, + 0x08, 0x14, 0x2A, 0x14, 0x22, + 0x22, 0x14, 0x2A, 0x14, 0x08, + 0xAA, 0x00, 0x55, 0x00, 0xAA, + 0xAA, 0x55, 0xAA, 0x55, 0xAA, + 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x10, 0x10, 0x10, 0xFF, 0x00, + 0x14, 0x14, 0x14, 0xFF, 0x00, + 0x10, 0x10, 0xFF, 0x00, 0xFF, + 0x10, 0x10, 0xF0, 0x10, 0xF0, + 0x14, 0x14, 0x14, 0xFC, 0x00, + 0x14, 0x14, 0xF7, 0x00, 0xFF, + 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x14, 0x14, 0xF4, 0x04, 0xFC, + 0x14, 0x14, 0x17, 0x10, 0x1F, + 0x10, 0x10, 0x1F, 0x10, 0x1F, + 0x14, 0x14, 0x14, 0x1F, 0x00, + 0x10, 0x10, 0x10, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0x1F, 0x10, + 0x10, 0x10, 0x10, 0x1F, 0x10, + 0x10, 0x10, 0x10, 0xF0, 0x10, + 0x00, 0x00, 0x00, 0xFF, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0xFF, 0x10, + 0x00, 0x00, 0x00, 0xFF, 0x14, + 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x1F, 0x10, 0x17, + 0x00, 0x00, 0xFC, 0x04, 0xF4, + 0x14, 0x14, 0x17, 0x10, 0x17, + 0x14, 0x14, 0xF4, 0x04, 0xF4, + 0x00, 0x00, 0xFF, 0x00, 0xF7, + 0x14, 0x14, 0x14, 0x14, 0x14, + 0x14, 0x14, 0xF7, 0x00, 0xF7, + 0x14, 0x14, 0x14, 0x17, 0x14, + 0x10, 0x10, 0x1F, 0x10, 0x1F, + 0x14, 0x14, 0x14, 0xF4, 0x14, + 0x10, 0x10, 0xF0, 0x10, 0xF0, + 0x00, 0x00, 0x1F, 0x10, 0x1F, + 0x00, 0x00, 0x00, 0x1F, 0x14, + 0x00, 0x00, 0x00, 0xFC, 0x14, + 0x00, 0x00, 0xF0, 0x10, 0xF0, + 0x10, 0x10, 0xFF, 0x10, 0xFF, + 0x14, 0x14, 0x14, 0xFF, 0x14, + 0x10, 0x10, 0x10, 0x1F, 0x00, + 0x00, 0x00, 0x00, 0xF0, 0x10, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, + 0x38, 0x44, 0x44, 0x38, 0x44, + 0x7C, 0x2A, 0x2A, 0x3E, 0x14, + 0x7E, 0x02, 0x02, 0x06, 0x06, + 0x02, 0x7E, 0x02, 0x7E, 0x02, + 0x63, 0x55, 0x49, 0x41, 0x63, + 0x38, 0x44, 0x44, 0x3C, 0x04, + 0x40, 0x7E, 0x20, 0x1E, 0x20, + 0x06, 0x02, 0x7E, 0x02, 0x02, + 0x99, 0xA5, 0xE7, 0xA5, 0x99, + 0x1C, 0x2A, 0x49, 0x2A, 0x1C, + 0x4C, 0x72, 0x01, 0x72, 0x4C, + 0x30, 0x4A, 0x4D, 0x4D, 0x30, + 0x30, 0x48, 0x78, 0x48, 0x30, + 0xBC, 0x62, 0x5A, 0x46, 0x3D, + 0x3E, 0x49, 0x49, 0x49, 0x00, + 0x7E, 0x01, 0x01, 0x01, 0x7E, + 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, + 0x44, 0x44, 0x5F, 0x44, 0x44, + 0x40, 0x51, 0x4A, 0x44, 0x40, + 0x40, 0x44, 0x4A, 0x51, 0x40, + 0x00, 0x00, 0xFF, 0x01, 0x03, + 0xE0, 0x80, 0xFF, 0x00, 0x00, + 0x08, 0x08, 0x6B, 0x6B, 0x08, + 0x36, 0x12, 0x36, 0x24, 0x36, + 0x06, 0x0F, 0x09, 0x0F, 0x06, + 0x00, 0x00, 0x18, 0x18, 0x00, + 0x00, 0x00, 0x10, 0x10, 0x00, + 0x30, 0x40, 0xFF, 0x01, 0x01, + 0x00, 0x1F, 0x01, 0x01, 0x1E, + 0x00, 0x19, 0x1D, 0x17, 0x12, + 0x00, 0x3C, 0x3C, 0x3C, 0x3C, + 0x00, 0x00, 0x00, 0x00, 0x00 +}; diff --git a/drivers/qwiic/util/font8x16.h b/drivers/qwiic/util/font8x16.h new file mode 100644 index 0000000000..c070e4ec8c --- /dev/null +++ b/drivers/qwiic/util/font8x16.h @@ -0,0 +1,127 @@ +/****************************************************************************** +font8x16.h +Definition for medium font + +This file was imported from the MicroView library, written by GeekAmmo +(https://github.com/geekammo/MicroView-Arduino-Library), and released under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Modified by: +Emil Varughese @ Edwin Robotics Pvt. Ltd. +July 27, 2015 +https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/ +******************************************************************************/ +#pragma once + +#include "progmem.h" + +static const unsigned char font8x16[] PROGMEM = { + // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) + 8,16,32,96,2,56, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xBE, 0x90, 0xD0, 0xBE, 0x90, 0x00, + 0x00, 0x1C, 0x62, 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x0C, 0x12, 0x92, 0x4C, 0xB0, 0x88, 0x06, 0x00, + 0x80, 0x7C, 0x62, 0xB2, 0x1C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xE0, 0x18, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, + 0x00, 0x24, 0x18, 0x7E, 0x18, 0x24, 0x00, 0x00, 0x80, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, 0x00, 0x00, + 0xF8, 0x04, 0xC2, 0x32, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x04, 0x04, 0xFE, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x82, 0x42, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x02, 0x22, 0x22, 0x22, 0xDC, 0x00, 0x00, + 0xC0, 0xA0, 0x98, 0x84, 0xFE, 0x80, 0x80, 0x00, 0x00, 0x1E, 0x12, 0x12, 0x22, 0xC2, 0x00, 0x00, + 0xF8, 0x44, 0x22, 0x22, 0x22, 0xC0, 0x00, 0x00, 0x00, 0x02, 0x02, 0xC2, 0x32, 0x0A, 0x06, 0x00, + 0x00, 0x8C, 0x52, 0x22, 0x52, 0x8C, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x26, 0xF8, 0x00, 0x00, + 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, + 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x02, 0x82, 0x42, 0x22, 0x1C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x04, 0x0F, 0x04, 0x03, 0x00, 0x00, 0x04, 0x02, 0x01, 0x03, 0x04, 0x04, 0x03, 0x00, + 0x03, 0x04, 0x04, 0x04, 0x05, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x06, 0x08, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x06, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x03, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x04, 0x07, 0x04, 0x04, 0x00, 0x00, + 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, + 0x01, 0x02, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x04, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, + 0x04, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF8, 0x04, 0x72, 0x8A, 0xFA, 0x84, 0x78, 0x00, 0x00, 0xC0, 0x38, 0x06, 0x38, 0xC0, 0x00, 0x00, + 0x00, 0xFE, 0x22, 0x22, 0x22, 0xDC, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, + 0xFE, 0x02, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, 0x00, 0xFE, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, + 0x00, 0xFE, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x22, 0xE2, 0x00, 0x00, + 0xFE, 0x20, 0x20, 0x20, 0x20, 0xFE, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x02, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x02, 0xFE, 0x00, 0x00, 0xFE, 0x40, 0xB0, 0x08, 0x04, 0x02, 0x00, 0x00, + 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x0C, 0x70, 0x80, 0x70, 0x0C, 0xFE, 0x00, + 0xFE, 0x0C, 0x30, 0xC0, 0x00, 0xFE, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, + 0xFE, 0x42, 0x42, 0x42, 0x22, 0x1C, 0x00, 0x00, 0xF8, 0x04, 0x02, 0x02, 0x04, 0xF8, 0x00, 0x00, + 0x00, 0xFE, 0x42, 0x42, 0xA2, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x42, 0x42, 0x80, 0x00, 0x00, + 0x02, 0x02, 0x02, 0xFE, 0x02, 0x02, 0x02, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, + 0x06, 0x38, 0xC0, 0x00, 0xC0, 0x38, 0x06, 0x00, 0x3E, 0xC0, 0xF0, 0x0E, 0xF0, 0xC0, 0x3E, 0x00, + 0x00, 0x06, 0x98, 0x60, 0x98, 0x06, 0x00, 0x00, 0x00, 0x06, 0x18, 0xE0, 0x18, 0x06, 0x00, 0x00, + 0x02, 0x02, 0xC2, 0x32, 0x0A, 0x06, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x02, 0x00, + 0x00, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, + 0x40, 0x30, 0x0C, 0x0C, 0x30, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x02, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x06, 0x01, 0x01, 0x01, 0x01, 0x01, 0x06, 0x00, + 0x00, 0x07, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, + 0x07, 0x04, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x04, 0x07, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x04, 0x07, 0x04, 0x04, 0x00, 0x00, + 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, + 0x00, 0x07, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x12, 0x11, 0x10, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x06, 0x01, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, + 0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, + 0x00, 0xE0, 0x10, 0x10, 0x10, 0xFE, 0x00, 0x00, 0x00, 0xE0, 0x90, 0x90, 0x90, 0xE0, 0x00, 0x00, + 0x00, 0x20, 0xFC, 0x22, 0x22, 0x22, 0x02, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, + 0x00, 0xFE, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x10, 0x10, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x10, 0x10, 0xF2, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x80, 0x40, 0x20, 0x10, 0x00, 0x00, + 0x00, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x20, 0x10, 0xF0, 0x20, 0x10, 0xF0, 0x00, + 0x00, 0xF0, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xE0, 0x00, 0x00, + 0x00, 0xF0, 0x20, 0x10, 0x10, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, + 0x00, 0xF0, 0x20, 0x10, 0x10, 0x70, 0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x90, 0x20, 0x00, 0x00, + 0x00, 0x20, 0x20, 0xFC, 0x20, 0x20, 0x20, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, + 0x00, 0x70, 0x80, 0x00, 0x80, 0x70, 0x00, 0x00, 0xF0, 0x00, 0xC0, 0x30, 0xC0, 0x00, 0xF0, 0x00, + 0x00, 0x30, 0xC0, 0xC0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x00, 0x80, 0x70, 0x00, 0x00, + 0x00, 0x10, 0x10, 0x90, 0x50, 0x30, 0x00, 0x00, 0x00, 0x80, 0x80, 0x7E, 0x02, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x7E, 0x80, 0x80, 0x00, 0x00, + 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, + 0x00, 0x07, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, + 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x24, 0x24, 0x22, 0x1F, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, + 0x00, 0x3F, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x3F, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x00, 0x00, 0x03, 0x04, 0x04, 0x02, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x04, 0x03, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x00, 0x01, 0x06, 0x01, 0x00, + 0x00, 0x06, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x20, 0x20, 0x31, 0x0E, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x05, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 41cc06a436..0e2ccfc2a9 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -15,15 +15,90 @@ */ #include "rev6.h" #include "qwiic.h" +#include "action_layer.h" +#include "matrix.h" + +#ifdef QWIIC_MICRO_OLED_ENABLE + +static uint8_t layer; +static bool queue_for_send = false; + +void draw_ui(void) { + clear_buffer(); + draw_string(0, 2, "LAYER", PIXEL_ON, NORM, 0); + draw_rect_filled_soft(32, 0, 11, 11, PIXEL_ON, NORM); + draw_char(35, 2, layer + 0x30, PIXEL_ON, XOR, 0); + + // for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + // for (uint8_t y = 0; y < MATRIX_COLS; y++) { + // if (x < 4) + // draw_pixel(0 + y, 11 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM); + // else + // draw_pixel(6 + y, 7 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM); + // } + // } + + uint8_t mods = get_mods(); + if (mods & MOD_LSFT) { + draw_rect_filled_soft(0, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(3, 14, "S", PIXEL_OFF, NORM, 0); + } else { + draw_string(3, 14, "S", PIXEL_ON, NORM, 0); + } + if (mods & MOD_LCTL) { + draw_rect_filled_soft(10, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(13, 14, "C", PIXEL_OFF, NORM, 0); + } else { + draw_string(13, 14, "C", PIXEL_ON, NORM, 0); + } + if (mods & MOD_LALT) { + draw_rect_filled_soft(20, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(23, 14, "A", PIXEL_OFF, NORM, 0); + } else { + draw_string(23, 14, "A", PIXEL_ON, NORM, 0); + } + if (mods & MOD_LGUI) { + draw_rect_filled_soft(30, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(33, 14, "G", PIXEL_OFF, NORM, 0); + } else { + draw_string(33, 14, "G", PIXEL_ON, NORM, 0); + } + + send_buffer(); +} + +uint32_t layer_state_set_kb(uint32_t state) { + state = layer_state_set_user(state); + layer = biton32(state); + queue_for_send = true; + return state; +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + queue_for_send = true; + return process_record_user(keycode, record); +} + +#endif void matrix_init_kb(void) { +#ifdef QWIIC_MICRO_OLED_ENABLE + queue_for_send = true; +#endif matrix_init_user(); } void matrix_scan_kb(void) { +#ifdef QWIIC_MICRO_OLED_ENABLE + if (queue_for_send) { + draw_ui(); + queue_for_send = false; + } +#endif matrix_scan_user(); } +#ifdef QWIIC_JOYSTIIC_ENABLE void joystiic_trigger_kb(uint8_t trigger, bool active) { switch (trigger) { case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break; @@ -33,3 +108,4 @@ void joystiic_trigger_kb(uint8_t trigger, bool active) { case JOYSTIIC_PRESS: active ? register_code(KC_P) : unregister_code(KC_P); break; } } +#endif diff --git a/keyboards/planck/rev6/rules.mk b/keyboards/planck/rev6/rules.mk index 0ee32f2ce9..1b5085f5bb 100644 --- a/keyboards/planck/rev6/rules.mk +++ b/keyboards/planck/rev6/rules.mk @@ -53,5 +53,5 @@ NKRO_ENABLE = yes # USB Nkey Rollover CUSTOM_MATRIX = yes # Custom matrix file AUDIO_ENABLE = yes RGBLIGHT_ENABLE = no -QWIIC_ENABLE += JOYSTIIC +QWIIC_ENABLE += MICRO_OLED # SERIAL_LINK_ENABLE = yes diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index 6d48321f92..f1551d2519 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -82,13 +82,11 @@ void layer_xor(uint32_t state); #define layer_or(state) #define layer_and(state) #define layer_xor(state) - -__attribute__((weak)) -uint32_t layer_state_set_user(uint32_t state); -__attribute__((weak)) -uint32_t layer_state_set_kb(uint32_t state); #endif +uint32_t layer_state_set_user(uint32_t state); +uint32_t layer_state_set_kb(uint32_t state); + /* pressed actions cache */ #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) /* The number of bits needed to represent the layer number: log2(32). */ From 4446a3781c3f4a61eacbffe20c002f7130a5c70c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 11 Oct 2018 13:06:17 -0400 Subject: [PATCH 5/6] faster buffer sending --- drivers/qwiic/micro_oled.c | 26 +++++++++++++++++++------- drivers/qwiic/micro_oled.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/qwiic/micro_oled.c b/drivers/qwiic/micro_oled.c index 46765f389c..1e6ed10005 100644 --- a/drivers/qwiic/micro_oled.c +++ b/drivers/qwiic/micro_oled.c @@ -43,6 +43,7 @@ uint16_t fontMapWidth; #define swap(a, b) { uint8_t t = a; a = b; b = t; } uint8_t micro_oled_transfer_buffer[20]; +static uint8_t micro_oled_screen_current[384] = { 0 }; static uint8_t micro_oled_screen_buffer[] = { /* LCD Memory organised in 64 horizontal pixel and 6 rows of byte B B .............B ----- @@ -145,7 +146,7 @@ void micro_oled_init(void) { send_command(0x40); send_command(DISPLAYON); //--turn on oled panel - //clear_screen(); // Erase hardware memory inside the OLED controller to avoid random data in memory. + clear_screen(); // Erase hardware memory inside the OLED controller to avoid random data in memory. send_buffer(); } @@ -217,19 +218,30 @@ void set_contrast(uint8_t contrast) { } /** \brief Transfer display buffer. - Bulk move the screen buffer to the SSD1306 controller's memory so that images/graphics drawn on the screen buffer will be displayed on the OLED. + Sends the updated buffer to the controller - the current status is checked before to save i2c exectution time */ void send_buffer(void) { uint8_t i, j; - for (i=0; i<6; i++) { - set_page_address(i); - set_column_address(0); - for (j=0;j<0x40;j++) { - send_data(micro_oled_screen_buffer[i*0x40+j]); + uint8_t page_addr = 0xFF; + for (i = 0; i < 6; i++) { + uint8_t col_addr = 0xFF; + for (j = 0; j < 0x40; j++) { + if (micro_oled_screen_buffer[i*0x40+j] != micro_oled_screen_current[i*0x40+j]) { + if (page_addr != i) { + set_page_address(i); + } + if (col_addr != j) { + set_column_address(j); + } + send_data(micro_oled_screen_buffer[i*0x40+j]); + micro_oled_screen_current[i*0x40+j] = micro_oled_screen_buffer[i*0x40+j]; + col_addr = j + 1; + } } } } + /** \brief Draw pixel with color and mode. Draw color pixel in the screen buffer's x,y position with NORM or XOR draw mode. */ diff --git a/drivers/qwiic/micro_oled.h b/drivers/qwiic/micro_oled.h index faa06313d1..8303b3910d 100644 --- a/drivers/qwiic/micro_oled.h +++ b/drivers/qwiic/micro_oled.h @@ -37,6 +37,7 @@ void send_command(uint8_t command); void send_data(uint8_t data); void set_page_address(uint8_t address); void set_column_address(uint8_t address); +void clear_screen(void); void clear_buffer(void); void send_buffer(void); void draw_pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode); From 531387c01cbe5504ca4e41541c6fb44412122758 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 11 Oct 2018 15:09:08 -0400 Subject: [PATCH 6/6] encoder display --- keyboards/planck/rev6/matrix.c | 5 +++ keyboards/planck/rev6/rev6.c | 58 ++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index e4ebe48acc..db6efc4d09 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -90,6 +90,9 @@ void dip_update(uint8_t index, bool active) { } __attribute__ ((weak)) void encoder_update(bool clockwise) { } +__attribute__ ((weak)) +void encoder_update_kb(uint8_t index, bool clockwise) { } + bool last_dip_switch[4] = {0}; #ifndef ENCODER_RESOLUTION @@ -114,9 +117,11 @@ uint8_t matrix_scan(void) { encoder_value += encoder_LUT[encoder_state & 0xF]; if (encoder_value >= ENCODER_RESOLUTION) { encoder_update(0); + encoder_update_kb(0, 0); } if (encoder_value <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise encoder_update(1); + encoder_update_kb(0, 1); } encoder_value %= ENCODER_RESOLUTION; diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 0e2ccfc2a9..931f09d259 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -22,6 +22,7 @@ static uint8_t layer; static bool queue_for_send = false; +static uint8_t encoder_value = 32; void draw_ui(void) { clear_buffer(); @@ -29,39 +30,51 @@ void draw_ui(void) { draw_rect_filled_soft(32, 0, 11, 11, PIXEL_ON, NORM); draw_char(35, 2, layer + 0x30, PIXEL_ON, XOR, 0); - // for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - // for (uint8_t y = 0; y < MATRIX_COLS; y++) { - // if (x < 4) - // draw_pixel(0 + y, 11 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM); - // else - // draw_pixel(6 + y, 7 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM); - // } - // } +#define MATRIX_DISPLAY_X 46 +#define MATRIX_DISPLAY_Y 1 + + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + for (uint8_t y = 0; y < MATRIX_COLS; y++) { + if (x < 4) + draw_pixel(MATRIX_DISPLAY_X + 2 + y, MATRIX_DISPLAY_Y + 2 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM); + else + draw_pixel(MATRIX_DISPLAY_X + 8 + y, MATRIX_DISPLAY_Y - 2 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM); + } + } + draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 16, 8, PIXEL_ON, NORM); + + + draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM); + draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM); + + +#define MOD_DISPLAY_X 0 +#define MOD_DISPLAY_Y 22 uint8_t mods = get_mods(); if (mods & MOD_LSFT) { - draw_rect_filled_soft(0, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); - draw_string(3, 14, "S", PIXEL_OFF, NORM, 0); + draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0); } else { - draw_string(3, 14, "S", PIXEL_ON, NORM, 0); + draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0); } if (mods & MOD_LCTL) { - draw_rect_filled_soft(10, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); - draw_string(13, 14, "C", PIXEL_OFF, NORM, 0); + draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0); } else { - draw_string(13, 14, "C", PIXEL_ON, NORM, 0); + draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0); } if (mods & MOD_LALT) { - draw_rect_filled_soft(20, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); - draw_string(23, 14, "A", PIXEL_OFF, NORM, 0); + draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0); } else { - draw_string(23, 14, "A", PIXEL_ON, NORM, 0); + draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0); } if (mods & MOD_LGUI) { - draw_rect_filled_soft(30, 12, 5 + (1 * 6), 11, PIXEL_ON, NORM); - draw_string(33, 14, "G", PIXEL_OFF, NORM, 0); + draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM); + draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0); } else { - draw_string(33, 14, "G", PIXEL_ON, NORM, 0); + draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0); } send_buffer(); @@ -79,6 +92,11 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } +void encoder_update_kb(uint8_t index, bool clockwise) { + encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64; + queue_for_send = true; +} + #endif void matrix_init_kb(void) {