🩹 Use custom I2C pins for OLED (#24970)

This commit is contained in:
alextrical 2022-12-12 22:11:09 +00:00 committed by Scott Lahteine
parent ac05f0cb8b
commit 8bafc1d9ae
3 changed files with 18 additions and 34 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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;
@ -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);