2022-06-15 16:37:27 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "hardware/i2c.h"
|
|
|
|
#include "hardware/gpio.h"
|
|
|
|
#include "common/pimoroni_common.hpp"
|
|
|
|
|
|
|
|
#include "common/pimoroni_i2c.hpp"
|
|
|
|
|
|
|
|
#include "libraries/pico_graphics/pico_graphics.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
namespace pimoroni {
|
|
|
|
|
|
|
|
class SH1107 : public DisplayDriver {
|
|
|
|
I2C &i2c;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool round;
|
2022-06-27 14:03:53 +01:00
|
|
|
static const uint8_t DEFAULT_I2C_ADDRESS = 0x3c;
|
|
|
|
static const uint8_t ALTERNATE_I2C_ADDRESS = 0x3d;
|
2022-06-15 16:37:27 +01:00
|
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
// Variables
|
|
|
|
//--------------------------------------------------
|
|
|
|
private:
|
2022-06-27 14:03:53 +01:00
|
|
|
uint8_t i2c_address = DEFAULT_I2C_ADDRESS;
|
2022-06-15 16:37:27 +01:00
|
|
|
|
|
|
|
public:
|
2022-06-27 14:03:53 +01:00
|
|
|
SH1107(uint16_t width, uint16_t height, I2C &i2c) : SH1107(width, height, i2c, DEFAULT_I2C_ADDRESS) {};
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
SH1107(uint16_t width, uint16_t height, I2C &i2c, uint8_t i2c_address) :
|
|
|
|
DisplayDriver(width, height, ROTATE_0),
|
|
|
|
i2c(i2c), i2c_address(i2c_address) {
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xae);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x20); // set memory addressing mode
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x00);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xb0); // set page start address
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xc0); // mirror vertically (for australian market)
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x00);
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x10);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x40);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xa0); // mirror horizontally
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xa6); // no inversion
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xff); // ??????!
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x3f); // confusion intensifies..
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xa4);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xd3); // set display offset
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x00);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xd5); // set display clock divide
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xf0);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xd9); // set precharge period
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x22);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xda); // set com pins hardware configuration
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x12);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xdb); // set vcomh
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x20);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x8d); // set dc-dc enable
|
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0x14);
|
2022-06-15 16:37:27 +01:00
|
|
|
|
2022-06-27 14:03:53 +01:00
|
|
|
i2c.reg_write_uint8(i2c_address, 0, 0xaf); // turn display on
|
2022-06-15 16:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void update(PicoGraphics *graphics) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void common_init();
|
|
|
|
void command(uint8_t command, size_t len = 0, const char *data = NULL);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|