diff options
-rw-r--r-- | keyboards/hadron/i2c.c | 166 | ||||
-rw-r--r-- | keyboards/hadron/i2c.h | 46 | ||||
-rw-r--r-- | keyboards/hadron/ver2/config.h | 6 | ||||
-rw-r--r-- | keyboards/hadron/ver2/keymaps/default/keymap.c | 121 | ||||
-rw-r--r-- | keyboards/hadron/ver2/keymaps/readme.md | 22 | ||||
-rw-r--r-- | keyboards/hadron/ver2/keymaps/side_numpad/keymap.c | 162 | ||||
-rw-r--r-- | keyboards/hadron/ver2/rules.mk | 32 | ||||
-rw-r--r-- | keyboards/hadron/ver2/ver2.c | 64 | ||||
-rw-r--r-- | keyboards/hadron/ver2/ver2.h | 2 | ||||
-rw-r--r-- | keyboards/hadron/ver3/config.h | 12 | ||||
-rw-r--r-- | keyboards/hadron/ver3/keymaps/default/config.h | 1 | ||||
-rw-r--r-- | keyboards/hadron/ver3/keymaps/default/keymap.c | 4 | ||||
-rw-r--r-- | keyboards/hadron/ver3/keymaps/readme.md | 24 | ||||
-rw-r--r-- | keyboards/hadron/ver3/rules.mk | 4 | ||||
-rw-r--r-- | keyboards/hadron/ver3/ver3.c | 222 |
15 files changed, 155 insertions, 733 deletions
diff --git a/keyboards/hadron/i2c.c b/keyboards/hadron/i2c.c deleted file mode 100644 index cd2b835d50..0000000000 --- a/keyboards/hadron/i2c.c +++ /dev/null @@ -1,166 +0,0 @@ -#include <util/twi.h> -#include <avr/io.h> -#include <stdlib.h> -#include <avr/interrupt.h> -#include <util/twi.h> -#include <stdbool.h> -#include "i2c.h" - -#ifdef USE_I2C - -// Limits the amount of we wait for any one i2c transaction. -// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is -// 9 bits, a single transaction will take around 90μs to complete. -// -// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit -// poll loop takes at least 8 clock cycles to execute -#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8 - -#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE) - -volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; - -static volatile uint8_t slave_buffer_pos; -static volatile bool slave_has_register_set = false; - -// Wait for an i2c operation to finish -inline static -void i2c_delay(void) { - uint16_t lim = 0; - while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT) - lim++; - - // easier way, but will wait slightly longer - // _delay_us(100); -} - -// Setup twi to run at 100kHz -void i2c_master_init(void) { - // no prescaler - TWSR = 0; - // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10. - // Check datasheets for more info. - TWBR = ((F_CPU/SCL_CLOCK)-16)/2; -} - -// Start a transaction with the given i2c slave address. The direction of the -// transfer is set with I2C_READ and I2C_WRITE. -// returns: 0 => success -// 1 => error -uint8_t i2c_master_start(uint8_t address) { - TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); - - i2c_delay(); - - // check that we started successfully - if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START)) - return 1; - - // send device address - TWDR = address; - TWCR = (1<<TWINT) | (1<<TWEN); - - i2c_delay(); - - if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) ) - return 1; // slave did not acknowledge - else - return 0; // success -} - - -// Finish the i2c transaction. -void i2c_master_stop(void) { - TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); - - uint16_t lim = 0; - while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT) - lim++; -} - -// Write one byte to the i2c slave. -// returns 0 => slave ACK -// 1 => slave NACK -uint8_t i2c_master_write(uint8_t data) { - TWDR = data; - TWCR = (1<<TWINT) | (1<<TWEN); - - i2c_delay(); - - // check if the slave acknowledged us - return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1; -} - -// Read one byte from the i2c slave. If ack=1 the slave is acknowledged, -// if ack=0 the acknowledge bit is not set. -// returns: byte read from i2c device -uint8_t i2c_master_read(int ack) { - TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA); - - i2c_delay(); - return TWDR; -} - -void i2c_reset_state(void) { - TWCR = 0; -} - -void i2c_slave_init(uint8_t address) { - TWAR = address << 0; // slave i2c address - // TWEN - twi enable - // TWEA - enable address acknowledgement - // TWINT - twi interrupt flag - // TWIE - enable the twi interrupt - TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN); -} - -ISR(TWI_vect); - -ISR(TWI_vect) { - uint8_t ack = 1; - switch(TW_STATUS) { - case TW_SR_SLA_ACK: - // this device has been addressed as a slave receiver - slave_has_register_set = false; - break; - - case TW_SR_DATA_ACK: - // this device has received data as a slave receiver - // The first byte that we receive in this transaction sets the location - // of the read/write location of the slaves memory that it exposes over - // i2c. After that, bytes will be written at slave_buffer_pos, incrementing - // slave_buffer_pos after each write. - if(!slave_has_register_set) { - slave_buffer_pos = TWDR; - // don't acknowledge the master if this memory loctaion is out of bounds - if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) { - ack = 0; - slave_buffer_pos = 0; - } - slave_has_register_set = true; - } else { - i2c_slave_buffer[slave_buffer_pos] = TWDR; - BUFFER_POS_INC(); - } - break; - - case TW_ST_SLA_ACK: - case TW_ST_DATA_ACK: - // master has addressed this device as a slave transmitter and is - // requesting data. - TWDR = i2c_slave_buffer[slave_buffer_pos]; - BUFFER_POS_INC(); - break; - - case TW_BUS_ERROR: // something went wrong, reset twi state - TWCR = 0; - default: - break; - } - // Reset everything, so we are ready for the next TWI interrupt - TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN); -} - - - -#endif diff --git a/keyboards/hadron/i2c.h b/keyboards/hadron/i2c.h deleted file mode 100644 index 7ecf6eb278..0000000000 --- a/keyboards/hadron/i2c.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include <stdint.h> - -#ifndef F_CPU -#define F_CPU 16000000UL -#endif - -#define I2C_READ 1 -#define I2C_WRITE 0 - -#define I2C_ACK 1 -#define I2C_NACK 0 - -#define SLAVE_BUFFER_SIZE 0x10 - -// i2c SCL clock frequency -#define SCL_CLOCK 800000L - -extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; - -void i2c_master_init(void); -uint8_t i2c_master_start(uint8_t address); -void i2c_master_stop(void); -uint8_t i2c_master_write(uint8_t data); -uint8_t i2c_master_read(int); -void i2c_reset_state(void); -void i2c_slave_init(uint8_t address); - - -static inline unsigned char i2c_start_read(unsigned char addr) { - return i2c_master_start((addr << 1) | I2C_READ); -} - -static inline unsigned char i2c_start_write(unsigned char addr) { - return i2c_master_start((addr << 1) | I2C_WRITE); -} - -// from SSD1306 scrips -extern unsigned char i2c_rep_start(unsigned char addr); -extern void i2c_start_wait(unsigned char addr); -extern unsigned char i2c_readAck(void); -extern unsigned char i2c_readNak(void); -extern unsigned char i2c_read(unsigned char ack); - -#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); diff --git a/keyboards/hadron/ver2/config.h b/keyboards/hadron/ver2/config.h index e051db209c..c992f7fe33 100644 --- a/keyboards/hadron/ver2/config.h +++ b/keyboards/hadron/ver2/config.h @@ -28,10 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MATRIX_COL_PINS { F6, F7, D6, C7, F5, F4, F1, F0, D2, D3, D5, B3, B2, B1, B0 } #define UNUSED_PINS - -#define USE_I2C -#define SSD1306OLED -#define OLED_ROTATE180 +// configure oled driver for the 128x32 oled +#define OLED_UPDATE_INTERVAL 33 // ~30fps /* ws2812 RGB LED*/ #define RGB_DI_PIN D4 diff --git a/keyboards/hadron/ver2/keymaps/default/keymap.c b/keyboards/hadron/ver2/keymaps/default/keymap.c index 8e3d50d3d7..f24239aa22 100644 --- a/keyboards/hadron/ver2/keymaps/default/keymap.c +++ b/keyboards/hadron/ver2/keymaps/default/keymap.c @@ -1,10 +1,4 @@ #include QMK_KEYBOARD_H -#ifdef USE_I2C -#include "i2c.h" -#endif -#ifdef SSD1306OLED -#include "ssd1306.h" -#endif //Following line allows macro to read current RGB settings extern rgblight_config_t rgblight_config; @@ -18,8 +12,8 @@ extern rgblight_config_t rgblight_config; #define _DVORAK 2 #define _LOWER 3 #define _RAISE 4 -#define _MOUSECURSOR 8 -#define _ADJUST 16 +#define _MOUSECURSOR 5 +#define _ADJUST 6 enum preonic_keycodes { QWERTY = SAFE_RANGE, @@ -307,115 +301,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } -//Functions for ver2 -#ifdef KEYBOARD_hadron_ver2 -#include <LUFA/Drivers/Peripheral/TWI.h> void matrix_init_user(void) { - #ifdef USE_I2C - i2c_master_init(); - #ifdef SSD1306OLED - // calls code for the SSD1306 OLED - _delay_ms(400); - TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000)); - iota_gfx_init(); // turns on the display - #endif - #endif - #ifdef AUDIO_ENABLE - startup_user(); - #endif -} - - -void matrix_scan_user(void) { - #ifdef SSD1306OLED - iota_gfx_task(); // this is what updates the display continuously - #endif -} - -void matrix_update(struct CharacterMatrix *dest, - const struct CharacterMatrix *source) { - if (memcmp(dest->display, source->display, sizeof(dest->display))) { - memcpy(dest->display, source->display, sizeof(dest->display)); - dest->dirty = true; - } -} -//assign the right code to your layers for OLED display -#define L_BASE 0 -#define L_LOWER 8 -#define L_RAISE 16 -#define L_FNLAYER 64 -#define L_NUMLAY 128 -#define L_NLOWER 136 -#define L_NFNLAYER 192 -#define L_MOUSECURSOR 256 -#define L_ADJUST 65560 - -void iota_gfx_task_user(void) { -#if DEBUG_TO_SCREEN - if (debug_enable) { - return; - } -#endif - - struct CharacterMatrix matrix; - - matrix_clear(&matrix); - matrix_write_P(&matrix, PSTR("USB: ")); -#ifdef PROTOCOL_LUFA - switch (USB_DeviceState) { - case DEVICE_STATE_Unattached: - matrix_write_P(&matrix, PSTR("Unattached")); - break; - case DEVICE_STATE_Suspended: - matrix_write_P(&matrix, PSTR("Suspended")); - break; - case DEVICE_STATE_Configured: - matrix_write_P(&matrix, PSTR("Connected")); - break; - case DEVICE_STATE_Powered: - matrix_write_P(&matrix, PSTR("Powered")); - break; - case DEVICE_STATE_Default: - matrix_write_P(&matrix, PSTR("Default")); - break; - case DEVICE_STATE_Addressed: - matrix_write_P(&matrix, PSTR("Addressed")); - break; - default: - matrix_write_P(&matrix, PSTR("Invalid")); - } +#ifdef AUDIO_ENABLE + startup_user(); #endif - -// Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below - - char buf[40]; - snprintf(buf,sizeof(buf), "Undef-%ld", layer_state); - matrix_write_P(&matrix, PSTR("\n\nLayer: ")); - switch (layer_state) { - case L_BASE: - matrix_write_P(&matrix, PSTR("Default")); - break; - case L_RAISE: - matrix_write_P(&matrix, PSTR("Raise")); - break; - case L_LOWER: - matrix_write_P(&matrix, PSTR("Lower")); - break; - case L_ADJUST: - matrix_write_P(&matrix, PSTR("ADJUST")); - break; - default: - matrix_write(&matrix, buf); - } - - // Host Keyboard LED Status - char led[40]; - snprintf(led, sizeof(led), "\n%s %s %s", - (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ", - (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ", - (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " "); - matrix_write(&matrix, led); - matrix_update(&display, &matrix); } - -#endif diff --git a/keyboards/hadron/ver2/keymaps/readme.md b/keyboards/hadron/ver2/keymaps/readme.md deleted file mode 100644 index 2f7641d185..0000000000 --- a/keyboards/hadron/ver2/keymaps/readme.md +++ /dev/null @@ -1,22 +0,0 @@ -# How to add your own keymap - -Folders can be named however you'd like (will be approved upon merging), or should follow the format with a preceding `_`: - - _[ISO 3166-1 alpha-2 code*]_[layout variant]_[layout name/author] - -\* See full list: https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements - -and contain the following files: - -* `keymap.c` -* `readme.md` *recommended* -* `config.h` *optional*, found automatically when compiling -* `Makefile` *optional*, found automatically when compling - -When adding your keymap to this list, keep it organised alphabetically (select list, edit->sort lines), and use this format: - - * **folder_name** description - -# List of Planck keymaps - -* **default** default Planck layout diff --git a/keyboards/hadron/ver2/keymaps/side_numpad/keymap.c b/keyboards/hadron/ver2/keymaps/side_numpad/keymap.c index c63ae93855..74f95b4b75 100644 --- a/keyboards/hadron/ver2/keymaps/side_numpad/keymap.c +++ b/keyboards/hadron/ver2/keymaps/side_numpad/keymap.c @@ -1,15 +1,4 @@ #include QMK_KEYBOARD_H -#include <LUFA/Drivers/Peripheral/TWI.h> -#ifdef AUDIO_ENABLE - #include "audio.h" -#endif -#ifdef USE_I2C -#include "i2c.h" -#endif -#ifdef SSD1306OLED -#include "ssd1306.h" -#endif -extern keymap_config_t keymap_config; //Following line allows macro to read current RGB settings extern rgblight_config_t rgblight_config; @@ -19,12 +8,12 @@ extern rgblight_config_t rgblight_config; // Layer names don't all need to be of the same length, obviously, and you can also skip them // entirely and just use numbers. #define _QWERTY 0 -#define _LOWER 3 -#define _RAISE 4 -#define _FNLAYER 6 -#define _NUMLAY 7 -#define _MOUSECURSOR 8 -#define _ADJUST 16 +#define _LOWER 1 +#define _RAISE 2 +#define _FNLAYER 3 +#define _NUMLAY 4 +#define _MOUSECURSOR 5 +#define _ADJUST 6 enum preonic_keycodes { QWERTY = SAFE_RANGE, @@ -41,10 +30,7 @@ enum preonic_keycodes { RGBLED_DECREASE_SAT, RGBLED_INCREASE_VAL, RGBLED_DECREASE_VAL, -}; - -enum macro_keycodes { - KC_DEMOMACRO, + DEMOMACRO, }; // Custom macros @@ -57,7 +43,6 @@ enum macro_keycodes { #define LT_MC(kc) LT(_MOUSECURSOR, kc) // L-ayer T-ap M-ouse C-ursor #define LT_RAI(kc) LT(_RAISE, kc) // L-ayer T-ap to Raise #define TG_NUMLAY TG(_NUMLAY) //Toggle for layer _NUMLAY -#define DEMOMACRO M(KC_DEMOMACRO) // My login macros const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -322,29 +307,20 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } return false; break; + case DEMOMACRO: + if (record->event.pressed) { + SEND_STRING("hello world"); + } + return false; + break; } return true; } void matrix_init_user(void) { - #ifdef USE_I2C - i2c_master_init(); - #ifdef SSD1306OLED - // calls code for the SSD1306 OLED - _delay_ms(400); - TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000)); - iota_gfx_init(); // turns on the display - #endif - #endif - #ifdef AUDIO_ENABLE - startup_user(); - #endif -} - -void matrix_scan_user(void) { - #ifdef SSD1306OLED - iota_gfx_task(); // this is what updates the display continuously - #endif +#ifdef AUDIO_ENABLE + startup_user(); +#endif } #ifdef AUDIO_ENABLE @@ -373,109 +349,3 @@ void music_scale_user(void) } #endif - -/* - * Macro definition - */ -const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) -{ - if (!eeconfig_is_enabled()) { - eeconfig_init(); - } - - switch (id) { - case KC_DEMOMACRO: - if (record->event.pressed){ - return MACRO (I(1), T(H),T(E),T(L), T(L), T(O), T(SPACE), T(W), T(O), T(R), T(L), T(D), END); - } - } - - return MACRO_NONE; -} - -void matrix_update(struct CharacterMatrix *dest, - const struct CharacterMatrix *source) { - if (memcmp(dest->display, source->display, sizeof(dest->display))) { - memcpy(dest->display, source->display, sizeof(dest->display)); - dest->dirty = true; - } -} - -//assign the right code to your layers for OLED display -#define L_BASE 0 -#define L_LOWER 8 -#define L_RAISE 16 -#define L_FNLAYER 64 -#define L_NUMLAY 128 -#define L_NLOWER 136 -#define L_NFNLAYER 192 -#define L_MOUSECURSOR 256 -#define L_ADJUST 65560 - -void iota_gfx_task_user(void) { -#if DEBUG_TO_SCREEN - if (debug_enable) { - return; - } -#endif - - struct CharacterMatrix matrix; - - matrix_clear(&matrix); - matrix_write_P(&matrix, PSTR("USB: ")); -#ifdef PROTOCOL_LUFA - switch (USB_DeviceState) { - case DEVICE_STATE_Unattached: - matrix_write_P(&matrix, PSTR("Unattached")); - break; - case DEVICE_STATE_Suspended: - matrix_write_P(&matrix, PSTR("Suspended")); - break; - case DEVICE_STATE_Configured: - matrix_write_P(&matrix, PSTR("Connected")); - break; - case DEVICE_STATE_Powered: - matrix_write_P(&matrix, PSTR("Powered")); - break; - case DEVICE_STATE_Default: - matrix_write_P(&matrix, PSTR("Default")); - break; - case DEVICE_STATE_Addressed: - matrix_write_P(&matrix, PSTR("Addressed")); - break; - default: - matrix_write_P(&matrix, PSTR("Invalid")); - } -#endif - -// Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below - - char buf[40]; - snprintf(buf,sizeof(buf), "Undef-%ld", layer_state); - matrix_write_P(&matrix, PSTR("\n\nLayer: ")); - switch (layer_state) { - case L_BASE: - matrix_write_P(&matrix, PSTR("Default")); - break; - case L_RAISE: - matrix_write_P(&matrix, PSTR("Raise")); - break; - case L_LOWER: - matrix_write_P(&matrix, PSTR("Lower")); - break; - case L_ADJUST: - matrix_write_P(&matrix, PSTR("ADJUST")); - break; - default: - matrix_write(&matrix, buf); - } - - // Host Keyboard LED Status - char led[40]; - snprintf(led, sizeof(led), "\n%s %s %s", - (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ", - (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ", - (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " "); - matrix_write(&matrix, led); - matrix_update(&display, &matrix); -} diff --git a/keyboards/hadron/ver2/rules.mk b/keyboards/hadron/ver2/rules.mk index f2ec0e7b3f..79e5cccb5e 100644 --- a/keyboards/hadron/ver2/rules.mk +++ b/keyboards/hadron/ver2/rules.mk @@ -5,27 +5,19 @@ MCU = atmega32u4 BOOTLOADER = halfkay # Build Options -# change to "no" to disable the options, or define them in the Makefile in -# the appropriate keymap folder that will get included automatically +# comment out to disable the options. # -BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite -MOUSEKEY_ENABLE = no # Mouse keys +BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite +MOUSEKEY_ENABLE = yes # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = no # Console for debug -COMMAND_ENABLE = no # Commands for debug and configuration -NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality -AUDIO_ENABLE = no # Audio output on port C6 -UNICODE_ENABLE = no # Unicode -RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. -SWAP_HANDS_ENABLE = no # Enable one-hand typing - +COMMAND_ENABLE = no # Commands for debug and configuration # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE -SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend - - -EXTRAFLAGS += -flto - - -SRC = i2c.c \ - ssd1306.c +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend +# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +NKRO_ENABLE = yes # USB Nkey Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +AUDIO_ENABLE = no # Audio output +RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight +OLED_ENABLE = yes +OLED_DRIVER = SSD1306 diff --git a/keyboards/hadron/ver2/ver2.c b/keyboards/hadron/ver2/ver2.c index f00b4f26d6..ca13427497 100644 --- a/keyboards/hadron/ver2/ver2.c +++ b/keyboards/hadron/ver2/ver2.c @@ -1 +1,65 @@ #include "ver2.h" + +#ifdef OLED_ENABLE +__attribute__ ((weak)) +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + return OLED_ROTATION_180; +} + +__attribute__ ((weak)) +void oled_task_user(void) { + oled_write_P(PSTR("LAYER "), false); + oled_write_char(get_highest_layer(layer_state) + 0x30, true); + + led_t led_state = host_keyboard_led_state(); + oled_set_cursor(18, 0); + oled_write_P(PSTR("NUM"), led_state.num_lock); + oled_set_cursor(18, 1); + oled_write_P(PSTR("CAP"), led_state.caps_lock); + oled_set_cursor(18, 2); + oled_write_P(PSTR("SCR"), led_state.scroll_lock); + + uint8_t mod_state = get_mods(); + oled_set_cursor(10, 3); + oled_write_P(PSTR("S"), mod_state & MOD_MASK_SHIFT); + oled_advance_char(); + oled_write_P(PSTR("C"), mod_state & MOD_MASK_CTRL); + oled_advance_char(); + oled_write_P(PSTR("A"), mod_state & MOD_MASK_ALT); + oled_advance_char(); + oled_write_P(PSTR("G"), mod_state & MOD_MASK_GUI); + oled_advance_char(); + +/* Matrix display is 12 x 12 pixels */ +#define MATRIX_DISPLAY_X 5 +#define MATRIX_DISPLAY_Y 18 + + // matrix + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + for (uint8_t y = 0; y < MATRIX_COLS; y++) { + bool on = (matrix_get_row(x) & (1 << y)) > 0; + oled_write_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2, on); + } + } + + // outline + for (uint8_t x = 0; x < 19; x++) { + oled_write_pixel(MATRIX_DISPLAY_X + x, MATRIX_DISPLAY_Y, true); + oled_write_pixel(MATRIX_DISPLAY_X + x, MATRIX_DISPLAY_Y + 9, true); + } + for (uint8_t y = 0; y < 9; y++) { + oled_write_pixel(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y+y, true); + oled_write_pixel(MATRIX_DISPLAY_X + 19, MATRIX_DISPLAY_Y+y, true); + } + + // oled location + for (uint8_t x = 0; x < 3; x++) { + oled_write_pixel(MATRIX_DISPLAY_X + 14 + x, MATRIX_DISPLAY_Y + 2, true); + } + + // bodge for layer number left hand side + for (uint8_t y = 0; y < 8; y++) { + oled_write_pixel(35, 0 + y, true); + } +} +#endif diff --git a/keyboards/hadron/ver2/ver2.h b/keyboards/hadron/ver2/ver2.h index e7577d2684..8127b497f7 100644 --- a/keyboards/hadron/ver2/ver2.h +++ b/keyboards/hadron/ver2/ver2.h @@ -1,3 +1,3 @@ #pragma once -#include "../hadron.h" +#include "hadron.h" diff --git a/keyboards/hadron/ver3/config.h b/keyboards/hadron/ver3/config.h index 87d01726f5..54fab6662d 100644 --- a/keyboards/hadron/ver3/config.h +++ b/keyboards/hadron/ver3/config.h @@ -69,16 +69,8 @@ #define AUDIO_CLICKY_FREQ_RANDOMNESS 1.5f #endif -//configure qwiic micro_oled driver for the 128x32 oled -#ifdef QWIIC_MICRO_OLED_ENABLE - -#undef I2C_ADDRESS_SA0_1 -#define I2C_ADDRESS_SA0_1 0b0111100 -#define LCDWIDTH 128 -#define LCDHEIGHT 32 -#define micro_oled_rotate_180 - -#endif +// configure oled driver for the 128x32 oled +#define OLED_UPDATE_INTERVAL 33 // ~30fps /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ // #define DEBOUNCE 6 diff --git a/keyboards/hadron/ver3/keymaps/default/config.h b/keyboards/hadron/ver3/keymaps/default/config.h deleted file mode 100644 index 6f70f09bee..0000000000 --- a/keyboards/hadron/ver3/keymaps/default/config.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/keyboards/hadron/ver3/keymaps/default/keymap.c b/keyboards/hadron/ver3/keymaps/default/keymap.c index cec43e95d4..b897ffcab1 100644 --- a/keyboards/hadron/ver3/keymaps/default/keymap.c +++ b/keyboards/hadron/ver3/keymaps/default/keymap.c @@ -9,8 +9,8 @@ #define _DVORAK 2 #define _LOWER 3 #define _RAISE 4 -#define _MOUSECURSOR 8 -#define _ADJUST 16 +#define _MOUSECURSOR 5 +#define _ADJUST 6 enum preonic_keycodes { QWERTY = SAFE_RANGE, diff --git a/keyboards/hadron/ver3/keymaps/readme.md b/keyboards/hadron/ver3/keymaps/readme.md deleted file mode 100644 index 66bf06b711..0000000000 --- a/keyboards/hadron/ver3/keymaps/readme.md +++ /dev/null @@ -1,24 +0,0 @@ -# How to add your own keymap - -Folders can be named however you'd like (will be approved upon merging), or should follow the format with a preceding `_`: - - _[ISO 3166-1 alpha-2 code*]_[layout variant]_[layout name/author] - -\* See full list: https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements - -and contain the following files: - -* `keymap.c` -* `readme.md` *recommended* -* `config.h` *optional*, found automatically when compiling -* `Makefile` *optional*, found automatically when compling - -When adding your keymap to this list, keep it organised alphabetically (select list, edit->sort lines), and use this format: - - * **folder_name** description - -# List of Hadron keymaps - -* **default** default Hadron layout -* **ishtob** ishtob's Hadron layout -* **sebaslayout** sebaslayout's Hadron layout
\ No newline at end of file diff --git a/keyboards/hadron/ver3/rules.mk b/keyboards/hadron/ver3/rules.mk index f3cc14b17d..ad753a5ff1 100644 --- a/keyboards/hadron/ver3/rules.mk +++ b/keyboards/hadron/ver3/rules.mk @@ -22,6 +22,6 @@ RGBLIGHT_ENABLE = yes RGB_MATRIX_ENABLE = no # once arm_rgb is implemented RGB_MATRIX_DRIVER = WS2812 HAPTIC_ENABLE += DRV2605L -QWIIC_ENABLE = yes -QWIIC_DRIVERS += MICRO_OLED +OLED_ENABLE = yes +OLED_DRIVER = SSD1306 ENCODER_ENABLER = yes diff --git a/keyboards/hadron/ver3/ver3.c b/keyboards/hadron/ver3/ver3.c index 0664bf4b0e..7eabe58558 100644 --- a/keyboards/hadron/ver3/ver3.c +++ b/keyboards/hadron/ver3/ver3.c @@ -14,9 +14,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "ver3.h" -#include "qwiic.h" -#include "action_layer.h" -#include "haptic.h" #ifdef RGB_MATRIX_ENABLE @@ -36,185 +33,66 @@ led_config_t g_led_config = { { #endif -uint8_t *o_fb; - -uint16_t counterst = 0; - - - -#ifdef QWIIC_MICRO_OLED_ENABLE - -/* screen off after this many milliseconds */ -#include "timer.h" -#define ScreenOffInterval 60000 /* milliseconds */ -static uint16_t last_flush; - -volatile uint8_t led_numlock = false; -volatile uint8_t led_capslock = false; -volatile uint8_t led_scrolllock = false; - -static uint8_t layer; -static bool queue_for_send = false; -static uint8_t encoder_value = 32; - +#ifdef OLED_ENABLE __attribute__ ((weak)) -void draw_ui(void) { - clear_buffer(); - last_flush = timer_read(); - send_command(DISPLAYON); - -/* Layer indicator is 41 x 10 pixels */ -#define LAYER_INDICATOR_X 5 -#define LAYER_INDICATOR_Y 0 - - draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0); - draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM); - draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0); +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + return OLED_ROTATION_180; +} -/* Matrix display is 19 x 9 pixels */ +__attribute__ ((weak)) +void oled_task_user(void) { + oled_write_P(PSTR("LAYER "), false); + oled_write_char(get_highest_layer(layer_state) + 0x30, true); + + led_t led_state = host_keyboard_led_state(); + oled_set_cursor(18, 0); + oled_write_P(PSTR("NUM"), led_state.num_lock); + oled_set_cursor(18, 1); + oled_write_P(PSTR("CAP"), led_state.caps_lock); + oled_set_cursor(18, 2); + oled_write_P(PSTR("SCR"), led_state.scroll_lock); + + uint8_t mod_state = get_mods(); + oled_set_cursor(10, 3); + oled_write_P(PSTR("S"), mod_state & MOD_MASK_SHIFT); + oled_advance_char(); + oled_write_P(PSTR("C"), mod_state & MOD_MASK_CTRL); + oled_advance_char(); + oled_write_P(PSTR("A"), mod_state & MOD_MASK_ALT); + oled_advance_char(); + oled_write_P(PSTR("G"), mod_state & MOD_MASK_GUI); + oled_advance_char(); + +/* Matrix display is 12 x 12 pixels */ #define MATRIX_DISPLAY_X 5 #define MATRIX_DISPLAY_Y 18 - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - for (uint8_t y = 0; y < MATRIX_COLS; y++) { - draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM); + // matrix + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + for (uint8_t y = 0; y < MATRIX_COLS; y++) { + bool on = (matrix_get_row(x) & (1 << y)) > 0; + oled_write_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2, on); + } } - } - draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM); - /* hadron oled location on thumbnail */ - draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM); -/* - draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM); - draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM); - -*/ - -/* Mod display is 41 x 16 pixels */ -#define MOD_DISPLAY_X 30 -#define MOD_DISPLAY_Y 18 - - uint8_t mods = get_mods(); - if (mods & MOD_LSFT) { - 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(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0); - } - if (mods & MOD_LCTL) { - 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(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0); - } - if (mods & MOD_LALT) { - 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(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0); - } - if (mods & MOD_LGUI) { - 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(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0); - } - -/* Lock display is 23 x 32 */ -#define LOCK_DISPLAY_X 100 -#define LOCK_DISPLAY_Y 0 - - if (led_numlock == true) { - draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM); - draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0); - } else if (led_numlock == false) { - draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0); - } - if (led_capslock == true) { - draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM); - draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0); - } else if (led_capslock == false) { - draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0); - } - if (led_scrolllock == true) { - draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM); - draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0); - } else if (led_scrolllock == false) { - draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0); - } - send_buffer(); -} - -void read_host_led_state(void) { - uint8_t leds = host_keyboard_leds(); - if (leds & (1 << USB_LED_NUM_LOCK)) { - if (led_numlock == false){ - led_numlock = true;} - } else { - if (led_numlock == true){ - led_numlock = false;} - } - if (leds & (1 << USB_LED_CAPS_LOCK)) { - if (led_capslock == false){ - led_capslock = true;} - } else { - if (led_capslock == true){ - led_capslock = false;} + // outline + for (uint8_t x = 0; x < 19; x++) { + oled_write_pixel(MATRIX_DISPLAY_X + x, MATRIX_DISPLAY_Y, true); + oled_write_pixel(MATRIX_DISPLAY_X + x, MATRIX_DISPLAY_Y + 9, true); } - if (leds & (1 << USB_LED_SCROLL_LOCK)) { - if (led_scrolllock == false){ - led_scrolllock = true;} - } else { - if (led_scrolllock == true){ - led_scrolllock = false;} + for (uint8_t y = 0; y < 9; y++) { + oled_write_pixel(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y+y, true); + oled_write_pixel(MATRIX_DISPLAY_X + 19, MATRIX_DISPLAY_Y+y, true); } -} - -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); -} - -bool encoder_update_user(uint8_t index, bool clockwise); -bool encoder_update_kb(uint8_t index, bool clockwise) { - if (!encoder_update_user(index, clockwise)) return false; - encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64; - queue_for_send = true; - return true; -} - -#endif + // oled location + for (uint8_t x = 0; x < 3; x++) { + oled_write_pixel(MATRIX_DISPLAY_X + 14 + x, MATRIX_DISPLAY_Y + 2, true); + } -void matrix_init_kb(void) { - queue_for_send = true; - matrix_init_user(); + // bodge for layer number left hand side + for (uint8_t y = 0; y < 8; y++) { + oled_write_pixel(35, 0 + y, true); + } } - -void matrix_scan_kb(void) { -if (queue_for_send) { -#ifdef QWIIC_MICRO_OLED_ENABLE - read_host_led_state(); - draw_ui(); #endif - queue_for_send = false; - } -#ifdef QWIIC_MICRO_OLED_ENABLE - if (timer_elapsed(last_flush) > ScreenOffInterval) { - send_command(DISPLAYOFF); /* 0xAE */ - } -#endif - if (counterst == 0) { - //testPatternFB(o_fb); - } - counterst = (counterst + 1) % 1024; - //rgblight_task(); - matrix_scan_user(); -} |