Цитата(AHTOXA @ Oct 11 2012, 20:33)

по ходу дела всегда можно что-то подправить/изменить/добавить.
Ну да, что и происходит.
Посмотри пожалуйста.
Код
template<typename cs_pin>
class TDisplay
{
private:
spi_base_t& spi;
typedef cs_pin LCD_CS;
Pin<2, 6, 'H'> LCD_RS; // H for Data, L for Command
Pin<1, 4, 'L'> LCD_RST; // Active 0, set to it during CSL
uint8_t status; // 1/0 - On/Off. OLED requires to be off when not in use
unsigned char *font;
uint8_t fontnumber, fontwidth, fontheight;
uint8_t x, y; // position on the screen
inline void select(void) { spi.lock(); LCD_CS::On(); }
inline void deselect(void) { LCD_CS::Off(); spi.unlock(); }
inline void send(uint8_t data) { spi << data; }
void send_array(uint8_t *data, uint16_t count)
{ select();
for(uint16_t i=0; i<count; i++)
spi << data[i];
deselect();
}
void send_command(uint8_t *data, uint16_t count);
void send_data(uint8_t *data, uint16_t count);
void goto_xy(uint8_t x, uint8_t y);
public:
TDisplay(uint8_t *init, spi_base_t& spiref): spi(spiref);
void Set_contrast(uint8_t data);
uint8_t getstatus(void);
void On(void); // Because of using OLED display
void Off(void); // Because of using OLED display
void SetFont(uint8_t num);
uint8_t GetFont(void);
void ClrLines(unsigned char startline, unsigned char linesnum); // Clear number of text lines
void ClrText(unsigned char line, unsigned char xpos, unsigned char length); // Clear part of the line
void putchar(unsigned char ch, uint8_t xpos, uint8_t ypos);
void putstring(char *string, uint8_t xpos, uint8_t ypos);
void ShowFont(unsigned char num);
}
И несколько начальных функций. Не надо-ли что-то подправить? Хотелось бы понять перед тем, как перейду к описанию public функций. И по-моему в конструкторе класса у меня наверняка есть грубые ошибки в синтаксисе, поскольку пишу по остаткам памяти многолетней давности.
Массив init приведён просто для референса. С ним как раз более-менее всё понятно.

Да, в качестве основы взят найденный на инете драйвер некоего аналогичного графического дисплея, некоторые комментарии не переведены

Код
const uint8_t init[] = {0x40, //Display start line 0
0xa1, //ADC reverse <<<< Probably need to be changed
0xc0, //Normal COM0...COM63
0xa6, //Display normal
0xa2, //Set Bias 1/9 (Duty 1/65)
0x2f, //Booster, Regulator and Follower On
0xf8, //Set internal Booster to 4x
0x00,
0x27, //Contrast set
0x81,
0x16,
0xac, //Set indicator
0x00, //0x01,
0xAF, //}; //Display on
0xb0, //Page start sddress 0
0x10, //Set Higher Column Start Address 0
0x00 //Set Lower Column Start Address 0
};
/**************** Functions **************************************************/
void TDisplay::send_command(uint8_t *data, uint16_t count)
{
LCD_RS::Off(); // switch to send command
send_array(data, count); // SPI CS controlled inside this function
}
void TDisplay::send_data(uint8_t *data, uint16_t count)
{
LCD_RS::On(); // switch to send data
send_array(data, count); // SPI CS controlled inside this function
}
// Set symbol position in text mode
//Parameter:
// x: X - Position on screen (0 - 127)
// y: Y - Position on screen (0 - 8)
void TDisplay::goto_xy(uint8_t x, uint8_t y);
{
uint8_t set[] = {0xb0, 0x10, 0x00}; //Control commands array
set[0] += y; //Y - Add Y Position to Set Page Start Address
set[1] += x >> 4; //High - Nibble auf Steuerbefehl addieren
set[2] += x & 0x0f; //Low - Nibble auf Steuerbefehl addieren
send_command(set, 3);
}
//TDisplay constructor
TDisplay::TDisplay(uint8_t *init, spi_base_t& spiref): spi(spiref)
{
LCD_RST::Off(); // unreset LCD
send_command((uint8_t *)init, sizeof(init)); // Initialization
for(uint8_t line=0; line<8; line++) // clear display memory
{
goto_xy(0, line);
spiref.select();
send(0);
spiref.deselect();
}
}