From 0f3a73025cc9213fe4c7727518402f533dcfd288 Mon Sep 17 00:00:00 2001
From: MakotoKurauchi <pluis@me.com>
Date: Fri, 22 Jun 2018 02:44:33 +0900
Subject: [PATCH] Fix Helix i2c wrong bit rate (#3207)

---
 keyboards/helix/i2c.c                           | 2 +-
 keyboards/helix/i2c.h                           | 2 +-
 keyboards/helix/rev2/keymaps/default/keymap.c   | 2 --
 keyboards/helix/rev2/keymaps/five_rows/keymap.c | 2 --
 keyboards/helix/rev2/keymaps/froggy/keymap.c    | 2 --
 keyboards/helix/rev2/keymaps/led_test/keymap.c  | 2 --
 keyboards/helix/ssd1306.c                       | 1 +
 7 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/keyboards/helix/i2c.c b/keyboards/helix/i2c.c
index 084c890c4..4bee5c639 100644
--- a/keyboards/helix/i2c.c
+++ b/keyboards/helix/i2c.c
@@ -34,7 +34,7 @@ void i2c_delay(void) {
   // _delay_us(100);
 }
 
-// Setup twi to run at 100kHz
+// Setup twi to run at 100kHz or 400kHz (see ./i2c.h SCL_CLOCK)
 void i2c_master_init(void) {
   // no prescaler
   TWSR = 0;
diff --git a/keyboards/helix/i2c.h b/keyboards/helix/i2c.h
index c15b6bc50..47cf6bd1b 100644
--- a/keyboards/helix/i2c.h
+++ b/keyboards/helix/i2c.h
@@ -15,7 +15,7 @@
 
 #define SLAVE_BUFFER_SIZE 0x10
 
-// i2c SCL clock frequency
+// i2c SCL clock frequency 400kHz
 #define SCL_CLOCK  400000L
 
 extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
diff --git a/keyboards/helix/rev2/keymaps/default/keymap.c b/keyboards/helix/rev2/keymaps/default/keymap.c
index 1a268b32d..8c0fd8d9f 100644
--- a/keyboards/helix/rev2/keymaps/default/keymap.c
+++ b/keyboards/helix/rev2/keymaps/default/keymap.c
@@ -6,7 +6,6 @@
 #include "lufa.h"
 #include "split_util.h"
 #endif
-#include "LUFA/Drivers/Peripheral/TWI.h"
 #ifdef AUDIO_ENABLE
   #include "audio.h"
 #endif
@@ -479,7 +478,6 @@ void matrix_init_user(void) {
     #endif
     //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
     #ifdef SSD1306OLED
-        TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
         iota_gfx_init(!has_usb());   // turns on the display
     #endif
 }
diff --git a/keyboards/helix/rev2/keymaps/five_rows/keymap.c b/keyboards/helix/rev2/keymaps/five_rows/keymap.c
index d4fabd5a2..05767efc0 100644
--- a/keyboards/helix/rev2/keymaps/five_rows/keymap.c
+++ b/keyboards/helix/rev2/keymaps/five_rows/keymap.c
@@ -6,7 +6,6 @@
 #include "lufa.h"
 #include "split_util.h"
 #endif
-#include "LUFA/Drivers/Peripheral/TWI.h"
 #ifdef AUDIO_ENABLE
   #include "audio.h"
 #endif
@@ -413,7 +412,6 @@ void matrix_init_user(void) {
     #endif
     //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
     #ifdef SSD1306OLED
-        TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
         iota_gfx_init(!has_usb());   // turns on the display
     #endif
 }
diff --git a/keyboards/helix/rev2/keymaps/froggy/keymap.c b/keyboards/helix/rev2/keymaps/froggy/keymap.c
index 69c41856b..c4f4c1fe2 100644
--- a/keyboards/helix/rev2/keymaps/froggy/keymap.c
+++ b/keyboards/helix/rev2/keymaps/froggy/keymap.c
@@ -6,7 +6,6 @@
 #include "lufa.h"
 #include "split_util.h"
 #endif
-#include "LUFA/Drivers/Peripheral/TWI.h"
 #ifdef AUDIO_ENABLE
   #include "audio.h"
 #endif
@@ -435,7 +434,6 @@ void matrix_init_user(void) {
     #endif
     //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
     #ifdef SSD1306OLED
-        TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
         iota_gfx_init(!has_usb());   // turns on the display
     #endif
 }
diff --git a/keyboards/helix/rev2/keymaps/led_test/keymap.c b/keyboards/helix/rev2/keymaps/led_test/keymap.c
index d597020d8..f28db6657 100644
--- a/keyboards/helix/rev2/keymaps/led_test/keymap.c
+++ b/keyboards/helix/rev2/keymaps/led_test/keymap.c
@@ -6,7 +6,6 @@
 #include "lufa.h"
 #include "split_util.h"
 #endif
-#include "LUFA/Drivers/Peripheral/TWI.h"
 #ifdef AUDIO_ENABLE
   #include "audio.h"
 #endif
@@ -477,7 +476,6 @@ void matrix_init_user(void) {
     #endif
     //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
     #ifdef SSD1306OLED
-        TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
         iota_gfx_init(!has_usb());   // turns on the display
     #endif
 }
diff --git a/keyboards/helix/ssd1306.c b/keyboards/helix/ssd1306.c
index b13060ef7..b3e55a67c 100644
--- a/keyboards/helix/ssd1306.c
+++ b/keyboards/helix/ssd1306.c
@@ -127,6 +127,7 @@ static int8_t capture_sendchar(uint8_t c) {
 bool iota_gfx_init(bool rotate) {
   bool success = false;
 
+  i2c_master_init();
   send_cmd1(DisplayOff);
   send_cmd2(SetDisplayClockDiv, 0x80);
   send_cmd2(SetMultiPlex, DisplayHeight - 1);