122 lines
3.2 KiB
C++
122 lines
3.2 KiB
C++
/*
|
|
* ssd1306.h
|
|
*
|
|
* Created on: 12 ôåâð. 2017 ã.
|
|
* Author: l-pro
|
|
*/
|
|
|
|
#ifndef SSD1306_H_
|
|
#define SSD1306_H_
|
|
|
|
#include <cstdint>
|
|
#include "stm32f4xx_hal.h"
|
|
|
|
namespace SSD1306 {
|
|
|
|
namespace ScrollStepInterval {
|
|
static constexpr uint8_t Frames_2 = 0b111;
|
|
static constexpr uint8_t Frames_3 = 0b100;
|
|
static constexpr uint8_t Frames_4 = 0b101;
|
|
static constexpr uint8_t Frames_5 = 0b000;
|
|
static constexpr uint8_t Frames_25 = 0b110;
|
|
static constexpr uint8_t Frames_64 = 0b001;
|
|
static constexpr uint8_t Frames_128 = 0b010;
|
|
static constexpr uint8_t Frames_256 = 0b011;
|
|
}
|
|
|
|
namespace Commands {
|
|
namespace Fundamental {
|
|
static constexpr uint8_t SetContrastControl = 0x81;
|
|
static constexpr uint8_t EntireDisplayONRamResume = 0xA4;
|
|
static constexpr uint8_t EntireDisplayONRamIgnore = 0xA5;
|
|
static constexpr uint8_t SetNormalDisplay = 0xA6;
|
|
static constexpr uint8_t SetInverseDisplay = 0xA7;
|
|
static constexpr uint8_t SetDisplayOFF = 0xAE;
|
|
static constexpr uint8_t SetDisplayON = 0xAF;
|
|
}
|
|
namespace Scrolling {
|
|
static constexpr uint8_t HorizontalScrollSetupRight = 0x26;
|
|
static constexpr uint8_t HorizontalScrollSetupLeft = 0x27;
|
|
static constexpr uint8_t Deactivatescroll = 0x2E;
|
|
static constexpr uint8_t Activatescroll = 0x2F;
|
|
}
|
|
|
|
namespace Addressing {
|
|
static constexpr uint8_t SetMemoryAddressingMode = 0x20;
|
|
static constexpr uint8_t SetColumnAddress = 0x21;
|
|
static constexpr uint8_t SetPageAddress = 0x22;
|
|
|
|
static constexpr uint8_t SetPageStartAddress = 0xB0;
|
|
}
|
|
|
|
namespace ChargePump {
|
|
static constexpr uint8_t ChargePumpSetting = 0x8D;
|
|
static constexpr uint8_t DisableChargePump = 0x10;
|
|
static constexpr uint8_t EnableChargePump = 0x14;
|
|
}
|
|
}
|
|
|
|
inline void command(I2C_HandleTypeDef* i2c, uint8_t c) {
|
|
// I2C
|
|
uint8_t buffer[2] = {0x00, c};
|
|
auto result = HAL_I2C_Master_Transmit(i2c, 0x78, buffer, sizeof(buffer), HAL_MAX_DELAY);
|
|
if(HAL_OK != result){
|
|
for(;;);
|
|
}
|
|
/*uint8_t control = 0x00; // Co = 0, D/C = 0
|
|
Wire.beginTransmission(_i2caddr);
|
|
Wire.write(control);
|
|
Wire.write(c);
|
|
Wire.endTransmission();*/
|
|
}
|
|
|
|
inline void setPage(I2C_HandleTypeDef* i2c, uint8_t page){
|
|
command(i2c, Commands::Addressing::SetPageStartAddress + page);
|
|
command(i2c, 0x00);
|
|
command(i2c, 0x10);
|
|
}
|
|
|
|
inline void writePixels(I2C_HandleTypeDef* i2c, uint8_t* pixels, uint16_t count){
|
|
/*command(i2c, Commands::Addressing::SetColumnAddress);
|
|
command(i2c, 0); // Column start address
|
|
command(i2c, 127); // Column end address
|
|
|
|
command(i2c, Commands::Addressing::SetPageAddress);
|
|
command(i2c, 0); // Page start address (0 = reset)
|
|
command(i2c, 7); // Page end address*/
|
|
|
|
|
|
|
|
/*uint8_t buffer[16 + 1];
|
|
buffer[0] = 0x40;
|
|
for(int i = 0; i < 16; ++i){
|
|
buffer[i + 1] = value;
|
|
}
|
|
|
|
HAL_I2C_Master_Transmit(i2c, 0x78, buffer, sizeof(buffer), HAL_MAX_DELAY);
|
|
*/
|
|
uint8_t buffer = 0x40;
|
|
//HAL_I2C_Master_Transmit(i2c, 0x78, &buffer, sizeof(buffer), HAL_MAX_DELAY);
|
|
pixels[0] = 0x40;
|
|
HAL_I2C_Master_Transmit(i2c, 0x78, pixels, count, HAL_MAX_DELAY);
|
|
|
|
|
|
/*for (uint16_t i = 0; i < (128*(64/8)); i++) {
|
|
|
|
HAL_I2C_Master_Transmit()
|
|
Wire.beginTransmission(_i2caddr);
|
|
WIRE_WRITE(0x40);
|
|
for (uint8_t x=0; x<16; x++) {
|
|
WIRE_WRITE(buffer[i]);
|
|
i++;
|
|
}
|
|
i--;
|
|
Wire.endTransmission();
|
|
}*/
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endif /* SSD1306_H_ */
|