Skip to content

Commit

Permalink
🩹 Use custom I2C pins for OLED (MarlinFirmware#24970)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextrical authored and thinkyhead committed Dec 16, 2022
1 parent ac05f0c commit 8bafc1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/tft/gt911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ void GT911::read_reg(uint16_t reg, uint8_t reg_len, uint8_t* r_data, uint8_t r_l
sw_iic.start();
sw_iic.send_byte(gt911_slave_address + 1); // Set read mode

LOOP_L_N(i, r_len) {
LOOP_L_N(i, r_len)
r_data[i] = sw_iic.read_byte(1); // Read data from reg
}

sw_iic.stop();
}

Expand Down
40 changes: 8 additions & 32 deletions Marlin/src/HAL/STM32/tft/gt911.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,18 @@ class SW_IIC {
private:
uint16_t scl_pin;
uint16_t sda_pin;
void write_scl(bool level)
{
WRITE(scl_pin, level);
}
void write_sda(bool level)
{
WRITE(sda_pin, level);
}
bool read_sda()
{
return READ(sda_pin);
}
void set_sda_out()
{
SET_OUTPUT(sda_pin);
}
void set_sda_in()
{
SET_INPUT_PULLUP(sda_pin);
}
static void iic_delay(uint8_t t)
{
delayMicroseconds(t);
}
void write_scl(bool level) { WRITE(scl_pin, level); }
void write_sda(bool level) { WRITE(sda_pin, level); }
bool read_sda() { return READ(sda_pin); }
void set_sda_out() { SET_OUTPUT(sda_pin); }
void set_sda_in() { SET_INPUT_PULLUP(sda_pin); }
static void iic_delay(uint8_t t) { delayMicroseconds(t); }

public:
SW_IIC(uint16_t sda, uint16_t scl);
// setSCL/SDA have to be called before begin()
void setSCL(uint16_t scl)
{
scl_pin = scl;
};
void setSDA(uint16_t sda)
{
sda_pin = sda;
};
void setSCL(uint16_t scl) { scl_pin = scl; }
void setSDA(uint16_t sda) { sda_pin = sda; }
void init(); // Initialize the IO port of IIC
void start(); // Send IIC start signal
void stop(); // Send IIC stop signal
Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;

#endif

#if HAS_U8GLIB_I2C_OLED && PINS_EXIST(I2C_SCL, I2C_SDA) && DISABLED(SOFT_I2C_EEPROM)
#include "Wire.h"
#endif

// Encoder Handling
#if HAS_ENCODER_ACTION
uint32_t MarlinUI::encoderPosition;
Expand Down Expand Up @@ -265,6 +269,10 @@ void MarlinUI::init() {
slow_buttons = 0;
#endif

#if HAS_U8GLIB_I2C_OLED && PINS_EXIST(I2C_SCL, I2C_SDA) && DISABLED(SOFT_I2C_EEPROM)
Wire.begin(int(I2C_SDA_PIN), int(I2C_SCL_PIN));
#endif

update_buttons();

TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);
Expand Down

0 comments on commit 8bafc1d

Please sign in to comment.