main
parent b89f3a2736
commit 56a320b922
  1. 137
      _48_2/_48_2.ino
  2. 1
      akva/_256-27nrf.ino.eep
  3. 4657
      akva/_256-27nrf.ino.hex
  4. 5125
      akva/_256-27nrf.ino.with_bootloader.hex
  5. 1093
      akva/_256-27nrf/_256-27nrf.ino
  6. 49
      akva/_256-27nrf/button/button_5.ino
  7. 115
      akva/_256-27nrf/button/sav_button.cpp
  8. 35
      akva/_256-27nrf/button/sav_button.h
  9. 78
      akva/_256-27nrf/button_.ino
  10. 38
      akva/_256-27nrf/data.ino
  11. 140
      akva/_256-27nrf/eeprom.ino
  12. 837
      akva/_256-27nrf/ir.ino
  13. 672
      akva/_256-27nrf/lamp_set.ino
  14. 187
      akva/_256-27nrf/m2.ino
  15. 274
      akva/_256-27nrf/menu_.ino
  16. 252
      akva/_256-27nrf/nagrlamp.ino
  17. 287
      akva/_256-27nrf/nagruzka.ino
  18. 391
      akva/_256-27nrf/night_set.ino
  19. 68
      akva/_256-27nrf/nrf24.ino
  20. 1520
      akva/_256-27nrf/pic.ino
  21. 315
      akva/_256-27nrf/settime.ino
  22. 358
      akva/_256-27nrf/temperatura.ino
  23. 288
      akva/_256-27nrf/timer_1.ino
  24. 688
      akva/_256-27nrf/timer_set.ino
  25. 2392
      akva/_256-27nrf/utility/chessengine.c
  26. 2030
      akva/_256-27nrf/utility/u8g.h
  27. 177
      akva/_256-27nrf/utility/u8g_bitmap.c
  28. 382
      akva/_256-27nrf/utility/u8g_circle.c
  29. 156
      akva/_256-27nrf/utility/u8g_clip.c
  30. 173
      akva/_256-27nrf/utility/u8g_com_api.c
  31. 94
      akva/_256-27nrf/utility/u8g_com_api_16gr.c
  32. 160
      akva/_256-27nrf/utility/u8g_com_arduino_attiny85_hw_spi.c
  33. 75
      akva/_256-27nrf/utility/u8g_com_arduino_common.c
  34. 254
      akva/_256-27nrf/utility/u8g_com_arduino_fast_parallel.c
  35. 438
      akva/_256-27nrf/utility/u8g_com_arduino_hw_spi.c
  36. 159
      akva/_256-27nrf/utility/u8g_com_arduino_hw_usart_spi.c
  37. 234
      akva/_256-27nrf/utility/u8g_com_arduino_no_en_parallel.c
  38. 184
      akva/_256-27nrf/utility/u8g_com_arduino_parallel.c
  39. 177
      akva/_256-27nrf/utility/u8g_com_arduino_port_d_wr.c
  40. 212
      akva/_256-27nrf/utility/u8g_com_arduino_ssd_i2c.c
  41. 330
      akva/_256-27nrf/utility/u8g_com_arduino_st7920_custom.c
  42. 293
      akva/_256-27nrf/utility/u8g_com_arduino_st7920_hw_spi.c
  43. 330
      akva/_256-27nrf/utility/u8g_com_arduino_st7920_spi.c
  44. 143
      akva/_256-27nrf/utility/u8g_com_arduino_std_sw_spi.c
  45. 301
      akva/_256-27nrf/utility/u8g_com_arduino_sw_spi.c
  46. 403
      akva/_256-27nrf/utility/u8g_com_arduino_t6963.c
  47. 206
      akva/_256-27nrf/utility/u8g_com_arduino_uc_i2c.c
  48. 188
      akva/_256-27nrf/utility/u8g_com_atmega_hw_spi.c
  49. 183
      akva/_256-27nrf/utility/u8g_com_atmega_parallel.c
  50. 216
      akva/_256-27nrf/utility/u8g_com_atmega_st7920_hw_spi.c
  51. 170
      akva/_256-27nrf/utility/u8g_com_atmega_st7920_spi.c
  52. 141
      akva/_256-27nrf/utility/u8g_com_atmega_sw_spi.c
  53. 643
      akva/_256-27nrf/utility/u8g_com_i2c.c
  54. 374
      akva/_256-27nrf/utility/u8g_com_io.c
  55. 221
      akva/_256-27nrf/utility/u8g_com_msp430_hw_spi.c
  56. 63
      akva/_256-27nrf/utility/u8g_com_null.c
  57. 124
      akva/_256-27nrf/utility/u8g_com_raspberrypi_hw_spi.c
  58. 176
      akva/_256-27nrf/utility/u8g_com_raspberrypi_ssd_i2c.c
  59. 140
      akva/_256-27nrf/utility/u8g_com_std_sw_spi.c
  60. 99
      akva/_256-27nrf/utility/u8g_cursor.c
  61. 310
      akva/_256-27nrf/utility/u8g_delay.c
  62. 199
      akva/_256-27nrf/utility/u8g_dev_a2_micro_printer.c
  63. 92
      akva/_256-27nrf/utility/u8g_dev_flipdisc_2x7.c
  64. 130
      akva/_256-27nrf/utility/u8g_dev_gprof.c
  65. 281
      akva/_256-27nrf/utility/u8g_dev_ht1632.c
  66. 326
      akva/_256-27nrf/utility/u8g_dev_ili9325d_320x240.c
  67. 110
      akva/_256-27nrf/utility/u8g_dev_ks0108_128x64.c
  68. 147
      akva/_256-27nrf/utility/u8g_dev_lc7981_160x80.c
  69. 145
      akva/_256-27nrf/utility/u8g_dev_lc7981_240x128.c
  70. 145
      akva/_256-27nrf/utility/u8g_dev_lc7981_240x64.c
  71. 151
      akva/_256-27nrf/utility/u8g_dev_lc7981_320x64.c
  72. 232
      akva/_256-27nrf/utility/u8g_dev_ld7032_60x32.c
  73. 67
      akva/_256-27nrf/utility/u8g_dev_null.c
  74. 141
      akva/_256-27nrf/utility/u8g_dev_pcd8544_84x48.c
  75. 138
      akva/_256-27nrf/utility/u8g_dev_pcf8812_96x65.c
  76. 107
      akva/_256-27nrf/utility/u8g_dev_sbn1661_122x32.c
  77. 289
      akva/_256-27nrf/utility/u8g_dev_ssd1306_128x32.c
  78. 412
      akva/_256-27nrf/utility/u8g_dev_ssd1306_128x64.c
  79. 187
      akva/_256-27nrf/utility/u8g_dev_ssd1306_64x48.c
  80. 142
      akva/_256-27nrf/utility/u8g_dev_ssd1309_128x64.c
  81. 338
      akva/_256-27nrf/utility/u8g_dev_ssd1322_nhd31oled_bw.c
  82. 338
      akva/_256-27nrf/utility/u8g_dev_ssd1322_nhd31oled_gr.c
  83. 263
      akva/_256-27nrf/utility/u8g_dev_ssd1325_nhd27oled_bw.c
  84. 232
      akva/_256-27nrf/utility/u8g_dev_ssd1325_nhd27oled_bw_new.c
  85. 255
      akva/_256-27nrf/utility/u8g_dev_ssd1325_nhd27oled_gr.c
  86. 227
      akva/_256-27nrf/utility/u8g_dev_ssd1325_nhd27oled_gr_new.c
  87. 299
      akva/_256-27nrf/utility/u8g_dev_ssd1327_96x96_gr.c
  88. 787
      akva/_256-27nrf/utility/u8g_dev_ssd1351_128x128.c
  89. 425
      akva/_256-27nrf/utility/u8g_dev_ssd1353_160x128.c
  90. 203
      akva/_256-27nrf/utility/u8g_dev_st7565_64128n.c
  91. 190
      akva/_256-27nrf/utility/u8g_dev_st7565_dogm128.c
  92. 157
      akva/_256-27nrf/utility/u8g_dev_st7565_dogm132.c
  93. 205
      akva/_256-27nrf/utility/u8g_dev_st7565_lm6059.c
  94. 236
      akva/_256-27nrf/utility/u8g_dev_st7565_lm6063.c
  95. 145
      akva/_256-27nrf/utility/u8g_dev_st7565_nhd_c12832.c
  96. 194
      akva/_256-27nrf/utility/u8g_dev_st7565_nhd_c12864.c
  97. 420
      akva/_256-27nrf/utility/u8g_dev_st7687_c144mvgd.c
  98. 175
      akva/_256-27nrf/utility/u8g_dev_st7920_128x64.c
  99. 151
      akva/_256-27nrf/utility/u8g_dev_st7920_192x32.c
  100. 154
      akva/_256-27nrf/utility/u8g_dev_st7920_202x32.c
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,137 @@
//mega 48 на погодной станции
#include <nrf24l01p.h>
#include <SPI.h>
enum
{
SPI_SS_PIN = 10,
NRF_CE_PIN = 8,//9
NRF_CHANNEL = 5,
NRF_POWER_UP_DELAY = 2,
NRF_PAYLOAD_LENGTH = 16
};
boolean mode;
char payload1[NRF_PAYLOAD_LENGTH];
char test_data[17] ;
void setup()
{
SPI.begin();
pinMode(SPI_SS_PIN, OUTPUT);
digitalWrite(SPI_SS_PIN, HIGH);
pinMode(NRF_CE_PIN, OUTPUT);
digitalWrite(NRF_CE_PIN, HIGH);
uint8_t address[5] = { 0xE2, 0xE4, 0x23, 0xE4, 0x02 };
nrf_initp(address);
pinMode(A5, OUTPUT);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
Serial.begin(9600);
Serial.println("Init");
}
//*****************************************************************************
void loop()
{digitalWrite(A5, LOW);
//Serial.println("Waiting for a packet...");
mode = digitalRead(9);//ожидаем приема с эфира для передачи по сериалу
if (mode==LOW)
{
do {} while (!(nrf24l01p_get_irq_flags() & (1 << NRF24L01P_IRQ_RX_DR)));
nrf24l01p_clear_irq_flag(NRF24L01P_IRQ_RX_DR);
static char payload[NRF_PAYLOAD_LENGTH];
nrf24l01p_read_rx_payload((uint8_t*)payload);//, sizeof(payload));
digitalWrite(A5, HIGH);
// Serial.print(">>");//передачи по сериалу
Serial.println(payload);
delay (200);
}
//*******************************
//***********************Передача в эфир при поступлении данных через сериал*************************************
if (Serial.available() > 0) {
for (int i=0;i<16;i++)
{// считываем входящий байт:1d24.8h50.0p7630 2u+07.10h63.8s92
test_data[i]= Serial.read();
}
// показываем, что именно мы получили:
// Serial.print("I received: ");
// Serial.println(test_data);
// delay(5000);
while(Serial.available()){Serial.read();}
digitalWrite(A5, HIGH);
delay (100);
digitalWrite(A5, LOW);
delay (100);
digitalWrite(NRF_CE_PIN, LOW);
uint8_t address[5] = { 0xE2, 0xE4, 0x23, 0xE4, 0x02 };
nrf_initr(address);
static uint8_t payload[NRF_PAYLOAD_LENGTH];
strcpy((char*)payload, test_data);
nrf24l01p_write_tx_payload(payload, sizeof(payload));
digitalWrite(NRF_CE_PIN, HIGH);
delay(1);
digitalWrite(NRF_CE_PIN, LOW);
do {} while (!(nrf24l01p_get_irq_flags() & (1 << NRF24L01P_IRQ_TX_DS)));
nrf24l01p_clear_irq_flag(NRF24L01P_IRQ_TX_DS);
Serial.println(" done");
nrf_initp(address);
digitalWrite(NRF_CE_PIN, HIGH);
digitalWrite(A5, HIGH);
}
delay (300);
//********************************************
}
//******************************************************************
void nrf_initp(uint8_t *address)//priem
{
delay(100);
nrf24l01p_get_clear_irq_flags();
nrf24l01p_close_pipe(NRF24L01P_ALL);
nrf24l01p_open_pipe(NRF24L01P_PIPE0, false);
nrf24l01p_set_crc_mode(NRF24L01P_CRC_16BIT);
nrf24l01p_set_address_width(NRF24L01P_AW_5BYTES);
nrf24l01p_set_address(NRF24L01P_PIPE0, address);
nrf24l01p_set_operation_mode(NRF24L01P_PRX);
nrf24l01p_set_rx_payload_width(NRF24L01P_PIPE0, NRF_PAYLOAD_LENGTH);
nrf24l01p_set_rf_channel(100);
nrf24l01p_set_power_mode(NRF24L01P_PWR_UP);
delay(NRF_POWER_UP_DELAY);
}
void nrf24l01p_spi_ss(nrf24l01p_spi_ss_level_t level)
{
digitalWrite(SPI_SS_PIN, (level == NRF24L01P_SPI_SS_LOW ? LOW : HIGH));
}
uint8_t nrf24l01p_spi_rw(uint8_t value)
{
return SPI.transfer(value);
}
void nrf_initr(uint8_t *address)//peredat
{
delay(200);
nrf24l01p_get_clear_irq_flags();
nrf24l01p_close_pipe(NRF24L01P_ALL);
nrf24l01p_open_pipe(NRF24L01P_TX, false);
nrf24l01p_set_rx_payload_width(NRF24L01P_PIPE0, NRF_PAYLOAD_LENGTH);
nrf24l01p_set_crc_mode(NRF24L01P_CRC_16BIT);
nrf24l01p_set_address_width(NRF24L01P_AW_5BYTES);
nrf24l01p_set_address(NRF24L01P_TX, address);
nrf24l01p_set_operation_mode(NRF24L01P_PTX);
nrf24l01p_set_rf_channel(5);
nrf24l01p_set_power_mode(NRF24L01P_PWR_UP);
delay(NRF_POWER_UP_DELAY);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,49 @@
/**
* Работа с кнопками
* Copyright (C) 2016 Alexey Shikharbeev
* http://samopal.pro
*/
#include "sav_button.h"
SButton button1(4,50,2000,4000,1000);
SButton button2(5,50,2000,4000,1000);
void setup()
{
Serial.begin(115200);
Serial.println("Test smart button ...");
// Инициация кнопок
button1.begin();
button2.begin();
}
void loop(){
switch( button1.Loop() ){
case SB_CLICK:
Serial.println("Press button 1");
break;
case SB_LONG_CLICK:
Serial.println("Long press button 1");
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 1");
break;
}
switch( button2.Loop() ){
case SB_CLICK:
Serial.println("Press button 2");
break;
case SB_LONG_CLICK:
Serial.println("Long press button 2");
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 2");
break;
}
}

@ -0,0 +1,115 @@
#include "sav_button.h"
/**
* Конструктор класса кнопки
* Кнопка это цифровой пин подтянутый к питанию и замыкаемый на землю
* Событие срабатывания происходит по нажатию кнопки (возвращается 1)
* и отпусканию кнопки (возвращается время нажатия кнопки, мсек)
* tm1 - таймаут дребезга контактов. По умолчанию 50мс
* tm2 - время длинного нажатия клавиши. По умолчанию 2000мс
* tm3 - врямы перевода кнопки в генерацию серии нажатий. По умолсанию отключено
* tm4 - время между кликами в серии. По умолчанию 500 мс. Если tm3 = 0 то не работает
*/
SButton::SButton(uint8_t pin,uint16_t tm1, uint16_t tm2,uint16_t tm3, uint16_t tm4){
Pin = pin;
State = false;
Long_press_state = false;
Auto_press_state = false;
Ms1 = 0;
Ms2 = 0;
Ms_auto_click = 0;
TM_bounce = tm1;
TM_long_click = tm2;
TM_auto_click = tm3;
Period_auto_click = tm4;
}
/**
* Инициализация кнопки
*/
void SButton::begin() {
pinMode(Pin, INPUT_PULLUP);
#ifdef DEBUG_SERIAL
Serial.print("Init button pin ");
Serial.println(Pin);
#endif
}
/**
* Действие производимое в цикле или по таймеру
* возвращает SB_NONE если кнопка не нажата и событие нажатие или динного нажатия кнопки
*/
SBUTTON_CLICK SButton::Loop() {
uint32_t ms = millis();
bool pin_state = digitalRead(Pin);
// Фиксируем нажатие кнопки
if( pin_state == LOW && State == false && (ms-Ms1)>TM_bounce ){
uint16_t dt = ms - Ms1;
Long_press_state = false;
Auto_press_state = false;
#ifdef DEBUG_SERIAL
Serial.print(">>>Event button, pin=");
Serial.print(Pin);
Serial.print(",press ON, tm=");
Serial.print(dt);
Serial.println(" ms");
#endif
State = true;
Ms2 = ms;
if( TM_long_click == 0 && TM_auto_click == 0 )return SB_CLICK;
}
// Фиксируем длинное нажатие кнопки
if( pin_state == LOW && !Long_press_state && TM_long_click>0 && ( ms - Ms2 )>TM_long_click ){
uint16_t dt = ms - Ms2;
Long_press_state = true;
#ifdef DEBUG_SERIAL
Serial.print(">>>Event button, pin=");
Serial.print(Pin);
Serial.print(",long press, tm=");
Serial.print(dt);
Serial.println(" ms");
#endif
return SB_LONG_CLICK;
}
// Фиксируем авто нажатие кнопки
if( pin_state == LOW && TM_auto_click > 0
&& ( ms - Ms2 ) > TM_auto_click
&& ( ms - Ms_auto_click ) > Period_auto_click ){
uint16_t dt = ms - Ms2;
Auto_press_state = true;
Ms_auto_click = ms;
#ifdef DEBUG_SERIAL
Serial.print(">>>Event button, pin=");
Serial.print(Pin);
Serial.print(",auto press, tm=");
Serial.print(dt);
Serial.println(" ms");
#endif
return SB_AUTO_CLICK;
}
// Фиксируем отпускание кнопки
if( pin_state == HIGH && State == true && (ms-Ms2)>TM_bounce ){
uint16_t dt = ms - Ms2;
// Сбрасываем все флаги
State = false;
#ifdef DEBUG_SERIAL
Serial.print(">>>Event button, pin=");
Serial.print(Pin);
Serial.print(",press OFF, tm=");
Serial.print(dt);
Serial.println(" ms");
#endif
Ms1 = ms;
// Возвращаем короткий клик
if( (TM_long_click != 0 || TM_auto_click != 0) && !Long_press_state && !Auto_press_state )return SB_CLICK;
}
return SB_NONE;
}

@ -0,0 +1,35 @@
#ifndef SavButton_h
#define SavButton_h
#include "Arduino.h"
//#define DEBUG_SERIAL 1
typedef enum {
SB_NONE = 0,
SB_CLICK,
SB_AUTO_CLICK,
SB_LONG_CLICK,
}SBUTTON_CLICK;
class SButton {
private :
uint8_t Pin;
bool State;
bool Long_press_state;
bool Auto_press_state;
uint32_t Ms1;
uint32_t Ms2;
uint32_t Ms_auto_click;
uint16_t TM_bounce;
uint16_t TM_long_click;
uint16_t TM_auto_click;
uint16_t Period_auto_click;
public :
SButton(uint8_t pin,uint16_t tm1 = 50, uint16_t tm2 = 0, uint16_t tm3 = 0, uint16_t tm4 = 500);
void begin();
SBUTTON_CLICK Loop();
};
#endif

@ -0,0 +1,78 @@
void but ()
{b=0;
switch( button1.Loop() ){
case SB_CLICK:
Serial.println("Press button 1");
b=1;
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 1");
b=11;
break;
}
switch( button2.Loop() ){
case SB_CLICK:
Serial.println("Press button 2");
b=2;
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 2");
b=12;
break;
}
switch( button3.Loop() ){
case SB_CLICK:
Serial.println("Press button 3");
b=3;
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 3");
b=13;
break;
}
switch( button4.Loop() ){
case SB_CLICK:
Serial.println("Press button 4");
b=4;
break;
case SB_LONG_CLICK:
Serial.println("Long press button 4");
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 4");
b=14;
break;
}
switch( button5.Loop() ){
case SB_CLICK:
Serial.println("Press button 5");
b=5;
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 5");
b=15;
break;
}
switch( button6.Loop() ){
case SB_CLICK:
Serial.println("Press button 6");
b=6;
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 6");
b=16;
break;
}
switch( button7.Loop() ){
case SB_CLICK:
Serial.println("Press button 7");
b=7;
break;
case SB_AUTO_CLICK:
Serial.println("Auto press button 7");
b=17;
break;
}
}

@ -0,0 +1,38 @@
void data()
{
// t1+103c375v299h9;
//strcpy((char*)payload1, test_data);
t1=tc1*10+td1;
osvet=osv;
t2=tc2*10+td2;
sprintf(s1,"0%d",tc1);
if (t1<100)
{sprintf(t11,"0%d",t1);
if (t1<10){sprintf(t11,"00%d",t1);}
}
else
{sprintf(t11,"%d",t1);
}
if (t2<100)
{sprintf(t22,"0%d",t2);
if (t2<10){sprintf(t22,"00%d",t2);}
}
else
{sprintf(t22,"%d",t2);
}
if (osvet<100)
{sprintf(osvet1,"0%d",osvet);
if (osvet<10){sprintf(osvet1,"00%d",osvet);}
}
else
{sprintf(osvet1,"%d",osvet);
}
sprintf (test_data, "t4+%sc%sc%sl%s",t11,osvet1,t22,s1);
}

@ -0,0 +1,140 @@
void savedat()
{
if(ntim==1)
{
for (int i =0 ; i < 23; i++)
{
EEPROM.update(i,timer_1[0][i]);
//EEPROM.write(i,timer_1[0][i]);
//EEPROM.write(i,7);
}
}
if(ntim==2)
{
for (int i =23 ; i < 46; i++)
{
EEPROM.update(i,timer_1[1][i-23]);
}
}
if(ntim==3)
{
for (int i =46 ; i < 69; i++)
{
EEPROM.update(i,timer_1[2][i-46]);
}
}
if(ntim==4)
{
for (int i =69 ; i < 92; i++)
{
EEPROM.update(i,timer_1[3][i-69]);
}
}
if(ntim==5)
{
for (int i =92 ; i < 115; i++)
{
EEPROM.update(i,timer_1[4][i-92]);
}
}
if(ntim==6)
{
for (int i =115 ; i < 138;i++)
{
EEPROM.update(i,timer_1[5][i-115]);
}
}
}
//*************Lamp1-4***********************************
void savedatlamp()
{ if(nlamp==1)
{
for (int i =138 ; i < 160; i++)
{
EEPROM.update(i,timer1amp[0][i-138]);
//EEPROM.write(i,timer_1[0][i]);
//EEPROM.write(i,7);
}
}
if(nlamp==2)
{
for (int i =160 ; i < 182; i++)
{
EEPROM.update(i,timer1amp[1][i-160]);
//EEPROM.write(i,timer_1[0][i]);
//EEPROM.write(i,7);
}
}
if(nlamp==3)
{
for (int i =182 ; i < 204; i++)
{
EEPROM.update(i,timer1amp[2][i-182]);
//EEPROM.write(i,timer_1[0][i]);
//EEPROM.write(i,7);
}
}
if(nlamp==4)
{
for (int i =204 ; i < 226; i++)
{
EEPROM.update(i,timer1amp[3][i-204]);
//EEPROM.write(i,timer_1[0][i]);
//EEPROM.write(i,7);
}
}
}
//************************************************************************
void savedatnight()
{
for (int i =226 ; i < 238; i++)
{
EEPROM.update(i,timernight[i-226]);
}
}
//**********************************************************************
void readdat()
{
int m=0;
for (int i =0 ; i < 6; i++)
{
for (int j =0 ; j < 23;j++)
{timer_1[i][j]=EEPROM.read(m);
m=m+1;
}
}
m=138;
for (int i =0 ; i < 4; i++)
{
for (int j =0 ; j < 22;j++)
{timer1amp[i][j]=EEPROM.read(m);
m=m+1;
}
}
lm1=timer1amp[0][11];
lm2=timer1amp[1][11];
lm3=timer1amp[2][11];
lm4=timer1amp[3][11];
m=226;
for (int j =0 ; j < 12;j++)
{timernight[j]=EEPROM.read(m);
m=m+1;
}
//night=timernight[0];
}

@ -0,0 +1,837 @@
void irem()
{
if (irrecv.decode(&results)) {
// Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
//on off E10332D
//photo E106678
//display E10EAF4
//datatime E10E6F8
//audiodub E10908E
//play E10504E
//rew E10405E
//FF E10C0DE
//pause E10607E
//stop E10001E
//leftstill E10E0FE
//rightstill E10F0EE
//menu E106A74
//enter E101A04
//right E904BD5
//left E90CB55
//up E900B95
//down E908B15
//search E90019F
//zoom T E104658
//zoom W E10C6D8
if(results.value == 0xE10504E) //play
{
mode=0;
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::White; // Белый цвет.
FastLED.show();
}
}
if(results.value == 0xE10001E)// stop
{
mode=0;
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Black; // OFF.
FastLED.show();
}
}
if(results.value == 0xE10E0FE) //leftstill E10E0FE
{
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(130, 70, 250)); // Сине-фиолетовый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(130, 70, 250)); // Сине-фиолетовый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(130, 70, 250)); // Сине-фиолетовый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
if(results.value == 0xE10F0EE) //rightstill E10F0EE
{
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(180, 110,190)); // Сиреневый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(180, 110,190)); // Сиреневый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(180, 110,190)); // Сиреневый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
if(results.value == 0xE101A04) //enter E101A04
{
//if(curm==0){curm=1;}
//curm=1;
}
//display E10EAF4
if(results.value == 0xE10EAF4) //display
{
//settimer=1;
menu=2;
}
if(results.value == 0xE10E6F8) //datatime E10E6F8
{settim=1;
}
if(results.value == 0xE90019F) //search E90019F
{ustt1=1;
}
if(results.value == 0xE10405E) //rew E10405E
{//timer1();
mode=7;//закат
s=1;
}
if(results.value == 0xE10C0DE) //ff
{
mode=6;//рассвет
s=1;
}
//*******************
if(results.value == 0xE106678) //E106678 foto
{//nigtset ();
menu=5;
}
//******************************
if(results.value == 0xE908B15) //down
{
if(curm==1){n1=!n1;}
if(curm==2){n2=!n2;}
if(curm==3){n3=!n3;}
if(curm==4){n4=!n4;}
if(curm==5){n5=!n5;}
if(curm==6)
{l1=l1-1;
if(l1<0){l1=0;}
}
if(curm==7)
{l2=l2-1;
if(l2<0){l2=0;}
}
if(curm==8)
{l3=l3-1;
if(l3<0){l3=0;}
}
if(curm>5)
{ulamp ();
}
else
{uprav ();
}
}
if(results.value == 0xE900B95) //up E900B95
{
if(curm==1){n1=!n1;}
if(curm==2){n2=!n2;}
if(curm==3){n3=!n3;}
if(curm==4){n4=!n4;}
if(curm==5){n5=!n5;}
if(curm==6)
{l1=l1+1;
if(l1>100){l1=100;}
}
if(curm==7)
{l2=l2+1;
if(l2>100){l2=100;}
}
if(curm==8)
{l3=l3+1;
if(l3>100){l3=100;}
}
if(curm>5)
{ulamp ();
}
else
{uprav ();
}
}
if(results.value == 0xE10908E) //audio
{
//lampse=1;
n5=0;// флаг таймера
fn=0;// флаг принуд вкл
digitalWrite(6, LOW); // выключает 5 timer
analogWrite(12,0);//выкл ламп
analogWrite(8,0);
}
if(results.value == 0xE90CB55) //left
{ curm--;
if(curm<1){curm=8;}
}
if(results.value == 0xE904BD5)//right
{curm++;
if(curm>8){curm=1;}
}
if(results.value == 0xE106A74) //menu
{
//menu=0;
if(curm>0){
curm=0;
nagruz ();
ulamp ();
}
}
if(results.value == 0xE10332D) //on off
//zoom W 10C6D8
{
}
if(results.value == 0xE104658) //zoom T 104658+
//zoom W 10C6D8
{
//analogWrite(8,250);
n5=1;// флаг таймера
fn=1;// флаг принуд вкл
digitalWrite(6, HIGH); // включает 5 timer
analogWrite(12,100);
}
if(results.value == 0xE10C6D8) //zoom W 10C6D8-
{n5=1;// флаг таймера
fn=1;// флаг принуд вкл
digitalWrite(6, HIGH); // включает 5 timer
analogWrite(8,250);
//analogWrite(12,250);
}
//*****************************************************************************************************
if (results.value == 0xFFB24D) { //FLASH
mode=1;
s=1;
}
if (results.value == 0xFF00FF) { //STROBE
mode=2;
s=1;
}
if (results.value == 0xFF58A7) { //FADE
mode=6;
s=1;
}
if (results.value == 0xFF30CF) { //FADE
mode=7;
s=1;
}
//************************************OFF*************************
if (results.value == 0xFFF807) {
mode=0;
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Black; // OFF.
FastLED.show();
}
}
//************************************On*************************
if (results.value == 0xFFB04F) {
mode=0;
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::White; // Белый цвет.
FastLED.show();
}
}
//************************************ ↑ *************************
if (results.value == 0xFF906F)
{
int b=20;
if (new_bright_f<100)
{b=10;
}
if (new_bright_f<50)
{b=5;
}
if (new_bright_f<10)
{b=1;
}
new_bright_f=new_bright_f+b;
if(new_bright_f>max_bright)
{
new_bright_f=max_bright;
}
LEDS.setBrightness(new_bright_f); // установить новую яркость
FastLED.show();
}
//************************************ ↓ *************************
if (results.value == 0xFFB847)
{
int b=20;
if (new_bright_f<100)
{b=10;
}
if (new_bright_f<50)
{b=5;
}
if (new_bright_f<10)
{b=1;
}
new_bright_f=new_bright_f-b;
if(new_bright_f<min_bright)
{
new_bright_f=min_bright;
}
LEDS.setBrightness(new_bright_f); // установить новую яркость
FastLED.show();
}
//********************************RED************************
if (results.value == 0xFF9867) {
if(mode==0)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Red; // Красный цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = CRGB::Red; //
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = CRGB::Red; //
//leds[3] = CRGB::Red; //
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************GREEN*************************
if (results.value == 0xFFD827) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Green; // Зеленый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = CRGB::Green; // Зеленый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = CRGB::Green; // Зеленый цвет.
//leds[3] = CRGB::Green; // Зеленый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************BLUE*************************
if (results.value == 0xFF8877) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Blue; // Синий цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = CRGB::Blue; // Синий цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = CRGB::Blue; // Синий цвет.
//leds[3] = CRGB::Blue; // Синий цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************White*************************
if (results.value == 0xFFA857) {
if(mode==6)mode=1;
if(mode==7)mode=1;
if(mode==0)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::White; // Белый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = CRGB::White; // Белый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = CRGB::White; // Белый цвет.
FastLED.show();
}
}
}
//*****************************ORANGE*************************
if (results.value == 0xFFE817) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(255, 50,0)); // Оранжевый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(255, 50,0)); // Оранжевый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(255, 50,0)); // Оранжевый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************AQUA*************************
if (results.value == 0xFF48B7) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Aqua; // Бирюзовый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = CRGB::Aqua; // Бирюзовый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = CRGB::Aqua; // Бирюзовый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Сине-фиолетовый*************************
if (results.value == 0xFF6897) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(100, 30, 220)); // Сине-фиолетовый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(100, 30, 220)); // Сине-фиолетовый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(100, 30, 220)); // Сине-фиолетовый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Светло-оранжевый*************************
if (results.value == 0xFF02FD) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(255, 80,20)); // Светло-оранжевый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(255, 80,20)); // Светло-оранжевый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(255, 80,20)); // Светло-оранжевый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Тёмно-берюзовый*************************
if (results.value == 0xFF32CD) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(59,131,189)); // Тёмно-берюзовый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(59,131,189)); // Тёмно-берюзовый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(59,131,189)); // Тёмно-берюзовый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Фиолетовый*************************
if (results.value == 0xFF20DF) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(139,0,255)); // Фиолетовый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(139,0,255)); // Фиолетовый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(139,0,255)); // Фиолетовый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Тёмно-жёлтый*************************
if (results.value == 0xFF50AF) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(250, 100,10)); // Тёмно-жёлтый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(250, 100,10)); // Тёмно-жёлтый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(250, 100,10)); // Тёмно-жёлтый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Голубой*************************
if (results.value == 0xFF7887) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(0, 97,255)); // Голубой цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(0, 97,255)); // Голубой цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(0, 97,255)); // Голубой цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Сиреневый*************************
if (results.value == 0xFF708F) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(80, 10,90)); // Сиреневый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(80, 10,90)); // Сиреневый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(80, 10,90)); // Сиреневый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*****************************Лимонный*************************
if (results.value == 0xFF38C7) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(253, 233,16)); // Лимонный
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(253, 233,16)); // Лимонный
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(253, 233,16)); // Лимонный
FastLED.show();
}
}
if(mode==6)mode=1;
}
//*****************************Светло-голубой*************************
if (results.value == 0xFF28D7) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(135, 206,250)); // Светло-голубой цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(135, 206,250)); // Светло-голубой цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(135, 206,250)); // Светло-голубой цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
}
//*****************************Розовый*************************
if (results.value == 0xFFF00F) {
if(mode==0)
{ for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = (CRGB(150, 10,150)); // Розовый цвет.
FastLED.show();
}
}
if(mode==1)
{
for (int i = 0; i < NUM_LEDS; i=i+2)
{
leds[i] = (CRGB(150, 10,150)); // Розовый цвет.
FastLED.show();
}
}
if(mode==2)
{
for (int i = 0; i < NUM_LEDS; i=i+4)
{
leds[i] = (CRGB(150, 10,150)); // Розовый цвет.
FastLED.show();
}
}
if(mode==6)mode=1;
if(mode==7)mode=1;
}
//*********************************************************************************************************
//if(pwmled==0){analogWrite(14, 1);}
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//result
}

@ -0,0 +1,672 @@
void lampset ()
{
boolean ret=0;
int cur=1;
int nlampold=nlamp;
int tu;
int td;
int tv;
int h1=0;
int m1=0;
int h2=0;
int m2=0;
int h3=0;
int m3=0;
int h4=0;
int m4=0;
int kan=1;
int lux1;
int time1=45;
int lux2=100;
int time2;
second1=0;
//data**************DATA*********************************************************************************
data:
tu=timer1amp[nlamp-1][0];
td=timer1amp[nlamp-1][1];
//tv=timer_1[nlamp-1][2];
kan=timer1amp[nlamp-1][2];
h1=timer1amp[nlamp-1][3];
m1=timer1amp[nlamp-1][4];
h2=timer1amp[nlamp-1][5];
m2=timer1amp[nlamp-1][6];
h3=timer1amp[nlamp-1][7];
m3=timer1amp[nlamp-1][8];
h4=timer1amp[nlamp-1][9];
m4=timer1amp[nlamp-1][10];
lux1=timer1amp[nlamp-1][11];
time1=timer1amp[nlamp-1][12];
lux2=timer1amp[nlamp-1][13];
time2=timer1amp[nlamp-1][14];
pn=timer1amp[nlamp-1][15];
vt=timer1amp[nlamp-1][16];
sr=timer1amp[nlamp-1][17];
cht=timer1amp[nlamp-1][18];
pt=timer1amp[nlamp-1][19];
sb=timer1amp[nlamp-1][20];
vs=timer1amp[nlamp-1][21];
//**************************DO***************************************************************************
do {
//irem();
// button();
delay (100);
second1++;
if (second1>1)
{ fl=!fl;
second1=0;
}
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, lamps);
// u8g.setColorIndex(0);
//u8g.setFont(u8g_font_04b_03br);//5x5
u8g.setFont(u8g_font_courR08);//7x5
// u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(50, 9);
u8g.print(nlamp,DEC); //nomer timer1ampa
// u8g.print(".");
u8g.setColorIndex(0);
u8g.setPrintPos(117, 9); //nomer kanala nagruzki
u8g.print(kan,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(24, 31); //vkl
if(h1<10){u8g.print("0");}
u8g.print(h1,DEC);
u8g.print(":");
if(m1<10){u8g.print("0");}
u8g.print(m1,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(84, 31); //vikl
if(h2<10){u8g.print("0");}
u8g.print(h2,DEC);
u8g.print(":");
if(m2<10){u8g.print("0");}
u8g.print(m2,DEC);
u8g.setFont(u8g_font_04b_03br);//5x5
if (lux1<10)
{u8g.setPrintPos(52, 39); //lux1
}
else
{u8g.setPrintPos(46, 39); //lux1
}
u8g.print(lux1,DEC);
l=lux1*26/100;
u8g.drawBox(16,35,l,3);
if (time1<10)
{u8g.setPrintPos(108, 39); //t1
}
else
{u8g.setPrintPos(103, 39); //t1
}
u8g.print(time1,DEC);
l=time1*26/60;
u8g.drawBox(74,35,l,3);
if (lux2<10)
{u8g.setPrintPos(52, 56); //lux2
}
else
{u8g.setPrintPos(46, 56); //lux2
}
u8g.print(lux2,DEC);
l=lux2*26/100;
u8g.drawBox(16,52,l,3);
if (time2<10)
{u8g.setPrintPos(108, 56); //t2
}
else
{u8g.setPrintPos(103, 56); //t2
}
u8g.print(time2,DEC);
l=time2*26/60;
u8g.drawBox(74,52,l,3);
u8g.setFont(u8g_font_courR08);//7x5
u8g.setPrintPos(24, 48); //vk2
if(h3<10){u8g.print("0");}
u8g.print(h3,DEC);
u8g.print(":");
if(m3<10){u8g.print("0");}
u8g.print(m3,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(84, 48); //vik2
if(h4<10){u8g.print("0");}
u8g.print(h4,DEC);
u8g.print(":");
if(m4<10){u8g.print("0");}
u8g.print(m4,DEC);
if(pn==1){u8g.drawBox(10,20,11,1);}
if(vt==1){u8g.drawBox(26,20,11,1);}
if(sr==1){u8g.drawBox(42,20,11,1);}
if(cht==1){u8g.drawBox(57,20,12,1);}
if(pt==1){u8g.drawBox(73,20,12,1);}
if(sb==1){u8g.drawBox(89,20,12,1);}
if(vs==1){u8g.drawBox(105,20,12,1);}
if(tu==0)
{ //u8g.setPrintPos(2, 32);// t1.1
u8g.setColorIndex(0);
u8g.drawBox(2,22,124,19);
u8g.setColorIndex(1);
u8g.setPrintPos(3, 31);// t1.1
u8g.print("OFF");
}
if(td==0)
{
u8g.setColorIndex(0);
u8g.drawBox(2,41,124,16);
u8g.setColorIndex(1);
u8g.setPrintPos(3, 49);// t1.1
u8g.print("OFF");
}
if (cur==1)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(50,1,6,9);
if(fl==1){u8g.setColorIndex(0);}
if(fl==0){u8g.setColorIndex(1);}
u8g.setPrintPos(50, 9);
u8g.print(nlamp,DEC); //nomer timer1ampa
}
if (cur==2)
{if(fl==1){u8g.setColorIndex(0);}
if(fl==0){u8g.setColorIndex(1);}
u8g.drawBox(117,1,6,9);
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.setPrintPos(117, 9); //nomer kanala nagruzki
u8g.print(kan,DEC);
}
if (cur==3){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(10,22,11,1);
}
if (cur==4){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(26,22,11,1);
}
if (cur==5){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(42,22,11,1);
}
if (cur==6){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(57,22,12,1);
}
if (cur==7){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(73,22,12,1);
}
if (cur==8){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(89,22,12,1);
}
if (cur==9){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(105,22,12,1);
}
//*************************************************
if (cur==10){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
if(tu==0)
{u8g.drawBox(3,32,18,1);
}
else
{u8g.drawBox(3,32,5,1);}
}
//*****************************vrem****************
if (cur==11){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,32,10,1);
}
if (cur==12){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(43,32,10,1);
}
if (cur==13){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(85,32,10,1);
}
if (cur==14){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(103,32,10,1);
}
//***********************************************
if (cur==15){//lux1
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(2,39,10,1);
}
//*********************** **********************
if (cur==16){//t1
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(67,39,5,1);
}
//***********************************************
if (cur==17){//2
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
if(td==0)
{u8g.drawBox(3,50,18,1);;
}
else
{u8g.drawBox(3,49,5,1);}
}
//*********************** **********************
if (cur==18){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,49,10,1);
}
if (cur==19){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(43,49,10,1);
}
if (cur==20){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(85,49,10,1);
}
if (cur==21){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(103,49,10,1);
}
//***********************************************
if (cur==22){//lux2
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(2,56,10,1);
}
//*********************** **********************
if (cur==23){//t2
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(67,56,5,1);
}
u8g.setColorIndex(1);
} while( u8g.nextPage() );
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE908B15) //down
{ if(cur==1)
{ nlamp=nlamp-1;
if (nlamp<1){nlamp=1;}
}
if(cur==2)
{ kan=kan-1;
if (kan<1){kan=1;}
}
if(cur==3)//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;// budilnik
{ if (pn==1)
{pn=0;
}
else{pn=1;
}
}
if(cur==4)
{ if (vt==1)
{vt=0;
}
else{vt=1;
}
}
if(cur==5)
{ if (sr==1)
{sr=0;
}
else{sr=1;
}
}
if(cur==6)
{ if (cht==1)
{cht=0;
}
else{cht=1;
}
}
if(cur==7)
{ if (pt==1)
{pt=0;
}
else{pt=1;
}
}
if(cur==8)
{ if (sb==1)
{sb=0;
}
else{sb=1;
}
}
if(cur==9)
{ if (vs==1)
{vs=0;
}
else{vs=1;
}
}
if(cur==10)
{tu=!tu;
}
if(cur==11)
{h1=h1-1;
if(h1<0){h1=23;}
}
if(cur==12)
{m1=m1-1;
if(m1<0){m1=59;}
}
if(cur==13)
{h2=h2-1;
if(h2<0){h2=23;}
}
if(cur==14)
{m2=m2-1;
if(m2<0){m2=59;}
}
if(cur==15)
{lux1=lux1-1;
if(lux1<0){lux1=0;}
}
if(cur==16)
{time1=time1-5;
if(time1<0){time1=0;}
}
if(cur==17)
{td=!td;
}
if(cur==18)
{h3=h3-1;
if(h3<0){h3=23;}
}
if(cur==19)
{m3=m3-1;
if(m3<0){m3=59;}
}
if(cur==20)
{h4=h4-1;
if(h4<0){h4=23;}
}
if(cur==21)
{m4=m4-1;
if(m4<0){m4=59;}
}
if(cur==22)
{lux2=lux2-1;
if(lux2<0){lux2=0;}
}
if(cur==23)
{time2=time2-5;
if(time2<0){time2=0;}
}
}
//*************************
if(results.value == 0xE900B95) //up E900B95
{ if(cur==1)
{ nlamp=nlamp+1;
if (nlamp>4){nlamp=4;}
}
if(cur==2)
{ kan=kan+1;
if (kan>4){kan=4;}
}
if(cur==3)//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;// budilnik
{ if (pn==1)
{pn=0;
}
else{pn=1;
}
}
if(cur==4)
{ if (vt==1)
{vt=0;
}
else{vt=1;
}
}
if(cur==5)
{ if (sr==1)
{sr=0;
}
else{sr=1;
}
}
if(cur==6)
{ if (cht==1)
{cht=0;
}
else{cht=1;
}
}
if(cur==7)
{ if (pt==1)
{pt=0;
}
else{pt=1;
}
}
if(cur==8)
{ if (sb==1)
{sb=0;
}
else{sb=1;
}
}
if(cur==9)
{ if (vs==1)
{vs=0;
}
else{vs=1;
}
}
if(cur==10)
{tu=!tu;
}
if(cur==11)
{h1=h1+1;
if(h1>23){h1=0;}
}
if(cur==12)
{m1=m1+1;
if(m1>59){m1=0;}
}
if(cur==13)
{h2=h2+1;
if(h2>23){h2=0;}
}
if(cur==14)
{m2=m2+1;
if(m2>59){m2=0;}
}
if(cur==15)
{lux1=lux1+1;
if(lux1>100){lux1=100;}
}
if(cur==16)
{time1=time1+5;
if(time1>60){time1=60;}
}
if(cur==17)
{td=!td;
}
if(cur==18)
{h3=h3+1;
if(h3>23){h3=0;}
}
if(cur==19)
{m3=m3+1;
if(m3>59){m3=0;}
}
if(cur==20)
{h4=h4+1;
if(h4>23){h4=0;}
}
if(cur==21)
{m4=m4+1;
if(m4>59){m4=0;}
}
if(cur==22)
{lux2=lux2+1;
if(lux2>100){lux2=100;}
}
if(cur==23)
{time2=time2+5;
if(time2>60){time2=60;}
}
}
if(results.value == 0xE904BD5) //right E904BD5
{
cur=cur+1;
if (cur==11)
{if (tu==0){cur=17;}
}
if (cur==18)
{if (td==0){cur=1;}
}
if (cur>23){cur=1;}
}
if(results.value == 0xE90CB55) //left E90CB55
{
cur=cur-1;
if (cur<1){cur=23;}
if (cur==23)
{if (td==0){cur=17;}
}
if (cur==16)
{if (tu==0){cur=10;}
}
}
if(results.value == 0xE101A04) //enter E101A04
{int a=tyes();
if(a==1)
{timer1amp[nlamp-1][0]=tu;
timer1amp[nlamp-1][1]=td;
timer1amp[nlamp-1][2]=kan;
timer1amp[nlamp-1][3]=h1;
timer1amp[nlamp-1][4]=m1;
timer1amp[nlamp-1][5]=h2;
timer1amp[nlamp-1][6]=m2;
timer1amp[nlamp-1][7]=h3;
timer1amp[nlamp-1][8]=m3;
timer1amp[nlamp-1][9]=h4;
timer1amp[nlamp-1][10]=m4;
timer1amp[nlamp-1][11]=lux1;
timer1amp[nlamp-1][12]=time1;
timer1amp[nlamp-1][13]=lux2;
timer1amp[nlamp-1][14]=time2;
timer1amp[nlamp-1][15]=pn;
timer1amp[nlamp-1][16]=vt;
timer1amp[nlamp-1][17]=sr;
timer1amp[nlamp-1][18]=cht;
timer1amp[nlamp-1][19]=pt;
timer1amp[nlamp-1][20]=sb;
timer1amp[nlamp-1][21]=vs;
savedatlamp();
nagruzlamp ();
}
settimer=0;
ret=1;
} //выход с сохранением
if(results.value == 0xE106A74) //menu E106A74
{
settimer=0;
ret=1;
} //выход без сохранения
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
//**********************PDY********************
but();
if((b == 1)|| (b == 11)) //menu E106A74
{
settimer=0;
ret=1;
} //выход без сохранения
if(nlamp!=nlampold)
{
nlampold=nlamp ;
goto data;
}
digitalWrite(13, LOW);
}while (ret<1);
lampse=0;
delay(300);
}

@ -0,0 +1,187 @@
void menu2 ()
{boolean ret=0;
byte secod1=0;
byte cur=1;
do {
DateTime now = rtc.now();
//*********************************
hour1 = now.hour();
minute1 = now.minute();
second1 = now.second();
//month1 =now.month();
//day1= now.day();
//year1 =now.year();
//****************************************
delay (100);
secod1++;
if (secod1==3)
{ fl=!fl;
secod1=0;
}
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, rabset);
//********************************************************************
u8g.setColorIndex(0);
//u8g.setFont(u8g_font_04b_03br);//5x5
//u8g.setFont(u8g_font_courR08);//7x5
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(30, 11);
u8g.print(hour1/10,DEC);
u8g.print(hour1%10,DEC);
u8g.print(":");
u8g.print(minute1/10,DEC);
u8g.print(minute1%10,DEC);
u8g.print(":");
u8g.print(second1/10,DEC);
u8g.print(second1%10,DEC);
//**********************************************************************
if (cur==1)
{ if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(37,20,49,1);
}
if (cur==2)
{ if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(6,35,11,1);}
if (cur==3)
{if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(40,35,13,1);}
if (cur==4)
{if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(74,35,11,1);}
if (cur==5)
{if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(108,35,13,1);}
if (cur==6)
{if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,53,7,1);}
if (cur==7)
{if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(61,53,7,1);}
if (cur==8)
{if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(91,53,12,1);}
} while( u8g.nextPage() );
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE908B15) //down
{ if(cur==2)
{
cur=6;
}
if(cur==1)
{
cur=2;
}
if(cur==3)
{
cur=7;
}
if((cur==4)||(cur==5))
{
cur=8;
}
}
if(results.value == 0xE900B95) //up E900B95
{ if(cur==2)
{cur=1;
}
if(cur==6)
{cur=2;
}
if(cur==8)
{cur=4;
}
if(cur==7)
{cur=3;
}
}
if(results.value == 0xE904BD5) //right E904BD5
{
cur=cur+1;
if (cur>8){cur=1;}
}
if(results.value == 0xE90CB55) //left E90CB55
{
cur=cur-1;
if (cur<1){cur=8;}
}
if(results.value == 0xE101A04) //enter E101A04
{
if(cur==1)
{menu=0;
settim=1;
ret=1;
}
if(cur==2)
{menu=0;
settimer=1;
ret=1;
}
if(cur==3)
{menu=0;
nigts=1;
ret=1;
}
if(cur==4)
{//menu=0;
//settim=1;
//ret=1;
}
if(cur==5)
{//menu=0;
// settim=1;
//ret=1;
}
if(cur==6)
{menu=0;
lampse=1;
ret=1;
}
if(cur==7)
{//menu=0;
//settim=1;
// ret=1;
}
if(cur==8)
{menu=0;
nigts=1;
ret=1;
}
}//выход в ....
if(results.value == 0xE106A74) //menu E106A74
{
menu=0;
ret=1;
} //выход без сохранения
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
}while (ret<1);
}

@ -0,0 +1,274 @@
//*********************************************************************
void menu10 ()
{
int value[72];
u8g.setFont(u8g_font_unifont);//8x12
u8g.setColorIndex(1);
u8g.setPrintPos(2, 11);
u8g.print(hour1/10,DEC);
u8g.print(hour1%10,DEC);
u8g.print(":");
u8g.print(minute1/10,DEC);
u8g.print(minute1%10,DEC);
u8g.print(":");
u8g.print(second1/10,DEC);
u8g.print(second1%10,DEC);
}
void menu0 ()
{
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, pogoda);
//********************************************************************
u8g.setColorIndex(0);
//u8g.setFont(u8g_font_04b_03br);//5x5
//u8g.setFont(u8g_font_courR08);//7x5
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(30, 11);
u8g.print(hour1/10,DEC);
u8g.print(hour1%10,DEC);
u8g.print(":");
u8g.print(minute1/10,DEC);
u8g.print(minute1%10,DEC);
u8g.print(":");
u8g.print(second1/10,DEC);
u8g.print(second1%10,DEC);
//**********************************************************************
u8g.setColorIndex(1);
u8g.setFont(u8g_font_04b_03br);//5x5
u8g.setPrintPos(42, 36);
//************L1********************************
if(mode==0){l1=l1;}//закат
if(mode==7){l1=(100-(mr77/44));}//закат
if(mode==6){l1=mr66/29;}//рассвет
u8g.print(l1);
l=lm1*25/100;//25 клеток на 100 процентов
u8g.drawBox(13,32,l,1);//установленные
l=l1*25/100;//25 клеток на 100 процентов
if(mode==0){l=0;}//закат
//if(mode==7){l=mr77*25/4370;}//закат
//if(mode==6){l=mr66*25/3600;}//рассвет
if(mode==7){l=l1/4;}//закат
if(mode==6){l=l1/4;}//рассвет
u8g.drawBox(13,33,l,2);//реальные
//******************************************
u8g.setPrintPos(42, 44);
u8g.print(l2,DEC);
l=lm2/4;
u8g.drawBox(13,40,l,1);
l=l2/4;
u8g.drawBox(13,41,l,2);
u8g.setPrintPos(42, 52);
u8g.print(l3,DEC);
l=lm3/4;
u8g.drawBox(13,48,l,1);
l=l3/4;
u8g.drawBox(13,49,l,2);
u8g.setFont(u8g_font_courR08);//7x5
u8g.setPrintPos(69, 20);
u8g.print("t1");
u8g.setPrintPos(69+25, 20);
u8g.print(tc1);
u8g.print(",");
u8g.print(td1);
u8g.setPrintPos(69, 30);
u8g.print("t2");
u8g.setPrintPos(69+25, 30);
u8g.print(tc2);
u8g.print(",");
u8g.print(td2);
u8g.setPrintPos(66, 41);
u8g.print("ph1");
u8g.setPrintPos(66+25, 41);
u8g.print(tc3);
u8g.print(",");
u8g.print(td3);
u8g.setPrintPos(66, 52);
u8g.print("ph2");
u8g.setPrintPos(69, 62);
u8g.print("sv");
if(css==0)
{u8g.setPrintPos(69+25, 62);
u8g.print(osv);
}
else
{
u8g.setPrintPos(69+20, 62);
u8g.print("s ");
u8g.print(osvs);
}
//***********************************************************************
if (n1==1){u8g.drawBox(7,21,4,4);}
if (n2==1){u8g.drawBox(19,21,4,4);}
if (n3==1){u8g.drawBox(31,21,4,4);}
if (n4==1){u8g.drawBox(43,21,4,4);}
if (n5==1){u8g.drawBox(55,21,4,4);}
//*********************CUR*************************************************
if (curm==1)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(5,28,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==2)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(17,28,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==3)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(29,28,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==4)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(41,28,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==5)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(53,28,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==6)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(3,37,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==7)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(3,45,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
if (curm==8)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(3,53,8,1);
if(fl==1){u8g.setColorIndex(0);}
}
}
//********************Свет включаем (обслуж аквы)****************
void menu5 ()
{
boolean m5=0;
boolean ml5=0;
int stmold=0;
int stm=0;//счетчик времени нахождения в режиме
// DateTime now = rtc.now();
// stmold = now.second();
int stmin;
int stsec;
//delay (350);
do {
delay (350);
DateTime now = rtc.now();
//*********************************
hour1 = now.hour();
minute1 = now.minute();
second1 = now.second();
month1 =now.month();
//****************************************
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, pogoda);
//********************************************************************
u8g.setColorIndex(0);
//u8g.setFont(u8g_font_04b_03br);//5x5
//u8g.setFont(u8g_font_courR08);//7x5
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(30, 11);
u8g.print(hour1/10,DEC);
u8g.print(hour1%10,DEC);
u8g.print(":");
u8g.print(minute1/10,DEC);
u8g.print(minute1%10,DEC);
u8g.print(":");
u8g.print(second1/10,DEC);
u8g.print(second1%10,DEC);
//**********************************************************************
u8g.setColorIndex(1);
u8g.setFont(u8g_font_courR08);//7x5
stmin=2700-stm;
stmin=stmin/60;
stsec=(2700-stm)-(stmin*60);
//u8g.print(stmin);
u8g.setPrintPos(11, 9);
u8g.print(":");
u8g.setPrintPos(0, 9);
u8g.print(stmin/10,DEC);
u8g.print(stmin%10,DEC);
u8g.setPrintPos(16, 9);
//u8g.print(stsec);
u8g.print(stsec/10,DEC);
u8g.print(stsec%10,DEC);
} while( u8g.nextPage() );
//***************************************************
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE106A74) //menu E106A74
{
stm=2701;
} //выход без сохранения
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
//***************************************************
if(ml5==0)
{ml5=1;
digitalWrite(6, HIGH); // включает светодиод
analogWrite(8,250);
analogWrite(12,250);
}
if(stmold!=second1)
{stmold=second1;
stm++;
}
if(stm>2700)// 45 min и автовыход
{m5=1;
menu=0;
analogWrite(8,0);
analogWrite(12,0);
digitalWrite(6, LOW); // включает светодиод
}
} while( m5<1 );
}

@ -0,0 +1,252 @@
void nagruzlamp ()
{
DateTime now = rtc.now();
//*********************************
hour1 = now.hour();
minute1 = now.minute();
second1 = now.second();
month1 =now.month();
day1= now.day();
year1 =now.year();
week=now.dayOfWeek();
if(week==0){week=7;}
//int tn;//заданное время вкл таймера
//int tno;//заданное время выкл таймера
//int tt;//время
tt=hour1*100+minute1;
//****************1************************
//int m=0;
ln1=0;
ln2=0;
ln3=0;
ln4=0;
for (int m=0 ; m < 4; m++)
{
if(timer1amp[m][week+14]==1)//week
{
if(timer1amp[m][0]==1)//1 on off
{
if (tt ==(timer1amp[m][5]*100+timer1amp[m][6]))//выкл
{ switch (timer1amp[m][2]) {
case 1:
ln1=0;
lampch1=2;
break;
case 2:
ln2=0;
lampch2=2;
break;
case 3:
ln3=0;
lampch3=2;
break;
case 4:
ln4=0;
lampch3=2;
break;
}
}//выкл 1 таймер tu
//вкл таймера лампа 1
if ((tt >= timer1amp[m][3]*100+timer1amp[m][4])&&(tt < timer1amp[m][5]*100+timer1amp[m][6]))
{
switch (timer1amp[m][2]) {
case 1:
ln1=1;
lm1=timer1amp[m][11];
sst1=timer1amp[m][12];//время плвного вкл лампы
lampch1=1;
break;
case 2:
ln2=1;
sst2=timer1amp[m][12];
lm2=timer1amp[m][11];
lampch2=1;
break;
case 3:
ln3=1;
sst3=timer1amp[m][12];
lm3=timer1amp[m][11];
lampch3=1;
break;
case 4:
ln4=1;
sst4=timer1amp[m][12];
lm4=timer1amp[m][11];
lampch4=1;
break;
}
}
}
//***********************************************************************************************
//*******2************************************************
//выкл лампа 2
if(timer1amp[m][1]==1)// -2
{ if (tt ==(timer1amp[m][9]*100+timer1amp[m][10]))
{ switch (timer1amp[m][2]) {
case 1:
ln1=0;
lampch1=2;
break;
case 2:
ln2=0;
lampch2=2;
break;
case 3:
ln3=0;
lampch3=2;
break;
case 4:
ln4=0;
lampch4=2;
break;
}
}
//****************************************************************************************
if ((tt >= timer1amp[m][7]*100+timer1amp[m][8])&&(tt < timer1amp[m][9]*100+timer1amp[m][10]))
{
switch (timer1amp[m][2]) {
case 1:
ln1=1;
sst1=timer1amp[m][14];
lm1=timer1amp[m][13];
lampch1=1;
break;
case 2:
ln2=1;
sst2=timer1amp[m][14];
lm2=timer1amp[m][13];
lampch2=1;
break;
case 3:
ln3=1;
sst3=timer1amp[m][14];
lm3=timer1amp[m][13];
lampch3=1;
break;
case 4:
ln4=1;
sst4=timer1amp[m][14];
lm4=timer1amp[m][13];
lampch4=1;
break;
}
}
}
//*****************3*******************************************************************
//*******************************************************************************************
}//week
}//timer
//ulamptimer ();
}
//**********************************************************************************************
void ulamptimer ()
{
int lamp;//l-текущее lm -max
//50 lum=960
if(night==0)//режим ночь выкл
{analogWrite(7,timernight[6]*255/100);//установка свечения LCD в режиме день
}
else
{analogWrite(7,timernight[5]*255/100);//установка свечения LCD в режиме ночь
}
//lamp=l1*255/100;
//analogWrite(7,lamp);
//digitalWrite(13, HIGH);
//***********LAMP2**************************************************
if (lampch2==1)
{if (ln2==1)
{st2++;
if(sst2==0)
{l2=lm2;
}
if(st2>((sst2*60/lm2)*220/255))//1pwm во времени в секундах
{l2++;
st2=0;
if (l2>lm2)
{l2=lm2;
lampch2=0;
}
lamp=l2*255/100;///0-255
analogWrite(8,lamp);
}
}
}
if (lampch2==2)
{if (ln2==0)
{st2++;
if(sst2==0)
{l2=0;
}
if(st2>((sst2*60/lm2)*220/255))//1pwm во времени в секундах
{l2=l2-1;
st2=0;
if (l2<1)
{l2=0;
lampch2=0;
}
lamp=l2*255/100;///0-255
analogWrite(8,lamp);
}
}
}
//***********************************************************************
//***********LAMP3**************************************************
if (lampch3==1)
{if (ln3==1)
{st3++;
if(sst3==0)
{l3=lm3;
}
if(st3>((sst3*60/lm3)*220/255))//1pwm во времени в секундах
{l3++;
st3=0;
if (l3>lm3)
{l3=lm3;
lampch3=0;
}
lamp=l3*255/100;///0-255
analogWrite(12,lamp);
}
}
}
if (lampch3==2)
{if (ln3==0)
{st3++;
if(sst3==0)
{l3=0;
}
if(st3>((sst3*60/lm3)*220/255))//1pwm во времени в секундах
{l3--;
st3=0;
if (l3<1)
{l3=0;
lampch3=0;
}
lamp=l3*255/100;
analogWrite(12,lamp);
}
}
}
//***********************************************************************
//delay(300);
//digitalWrite(13, LOW);
}

@ -0,0 +1,287 @@
void nagruz ()
{
DateTime now = rtc.now();
//*********************************
hour1 = now.hour();
minute1 = now.minute();
second1 = now.second();
month1 =now.month();
day1= now.day();
year1 =now.year();
week=now.dayOfWeek();
if(week==0){week=7;}
//int tt;//время
tt=hour1*100+minute1;
//****************1************************
//int m=0;
n1=0;
n2=0;
n3=0;
n4=0;
if(vent==0)
{n5=0;
}
if(fn==1)
{n5=1;
}
for (int m=0 ; m < 6; m++)//перебираем таймеры от 1(0) до 6(5)
{
if(timer_1[m][week+15]==1)//week
{
if(timer_1[m][0]==1)//1-3 on off
{
if ((tt >= timer_1[m][4]*100+timer_1[m][5])&&(tt < timer_1[m][6]*100+timer_1[m][7]))
{
switch (timer_1[m][3]) {
case 1:
n1=1;
timernumb=m;
break;
case 2:
n2=1;
break;
case 3:
n3=1;
break;
case 4:
n4=1;
break;
case 5:
n5=1;
break;
}
}
}
//*******2************************************************
if(timer_1[m][1]==1)
{
if ((tt >= timer_1[m][8]*100+timer_1[m][9])&&(tt < timer_1[m][10]*100+timer_1[m][11]))
{
switch (timer_1[m][3]) {
case 1:
n1=1;
timernumb=m;
break;
case 2:
n2=1;
break;
case 3:
n3=1;
break;
case 4:
n4=1;
break;
case 5:
n5=1;
break;
}
}
}
//*****************3*******************************************************************
if(timer_1[m][2]==1)
{
if ((tt >= timer_1[m][12]*100+timer_1[m][13])&&(tt < timer_1[m][14]*100+timer_1[m][15]))
{
switch (timer_1[m][3]) {
case 1:
n1=1;
timernumb=m;
break;
case 2:
n2=1;
break;
case 3:
n3=1;
break;
case 4:
n4=1;
break;
case 5:
n5=1;
break;
}
}
}//1-3 on off
//*******************************************************************************************
}//week
}//timer
uprav ();
//***************Режим ночь *************************************************************
night=0;
if (timernight[0]==1)
{if ( timernight[1]*100+timernight[2] > timernight[3]*100+timernight[4])
{ if ((tt >= timernight[1]*100+timernight[2])&&(tt <= 2359))
{//l=timernight[5]*255/100;
analogWrite(7,timernight[5]*255/100);
night=1;
//ulamptimer ();
}
if (tt < timernight[3]*100+timernight[4])
{//l=timernight[5]*255/100;
analogWrite(7,timernight[5]*255/100);
night=1;
// ulamptimer ();
}
}
if ( timernight[1]*100+timernight[2] < timernight[3]*100+timernight[4])
{ if ((tt >= timernight[1]*100+timernight[2])&&(tt < timernight[3]*100+timernight[4]))
{//l=timernight[5]*255/100;
analogWrite(7,timernight[5]*255/100);
night=1;
// ulamptimer ();
}
}
}
if(night==0)//режим ночь выкл
{analogWrite(7,timernight[6]*255/100);//установка свечения LCD в режиме день
}
else
{analogWrite(7,timernight[5]*255/100);//установка свечения LCD в режиме ночь
}
//**************************************************************************************************
}
void uprav ()
{
//***********UPR NAGRUZKOY*************************************************************
bool a=0;
if(n1==1)
{digitalWrite(2, HIGH); // включает светодиод
if(rasvet==0)
{mode=6;
s=1;
rasvet=1;
zakat=0;
}
}
else
{
digitalWrite(2, LOW);
if(zakat==0)
{mode=7;
s=1;
rasvet=0;
zakat=1;
}
}
if(n2==1)
{digitalWrite(3, HIGH); // включает светодиод
}
else
{
digitalWrite(3, LOW);
}
if(n3==1)
{digitalWrite(4, HIGH); // включает светодиод
}
else
{
digitalWrite(4, LOW);
}
if(n4==1)
{//a=digitalRead(5);
if(a==0)digitalWrite(5, HIGH); // включает светодиод#
}
else
{a=digitalRead(5);
if(a==1)digitalWrite(5, LOW);
}
if(n5==1)
{digitalWrite(6, HIGH); // включает светодиод
}
else
{if(vent==0)
{digitalWrite(6, LOW);
}
}
}
void ulamp ()
{
int lamp;
lamp=l1*255/100;
//analogWrite(7,lamp);
lamp=l2*255/100;
analogWrite(8,lamp);
lamp=l3*255/100;
analogWrite(12,lamp);
}
void rgb (){
//*****************************************************RGB *********************
//******* управление RGB лентой в 1 канале таймеров 1-6 те при n=1 ********
int tn;//заданное время вкл таймера
int tno;//заданное время выкл таймера
if(timer_1[timernumb][week+15]==1)//week
{
if(timer_1[timernumb][0]==1)//1-3 on off
{
tn=timer_1[timernumb][4]*100+timer_1[timernumb][5];
tno=timer_1[timernumb][6]*100+timer_1[timernumb][7];
if ((tt==tn )||(tt==tn+1 ))
{ mode=6;
s=1;
}
if ((tt==tno)||(tt==tno+1 ))
{ mode=7;
s=1;
}
}
if(timer_1[timernumb][1]==1)//1-3 on off
{
tn=timer_1[timernumb][8]*100+timer_1[timernumb][9];
tno=timer_1[timernumb][10]*100+timer_1[timernumb][11];
if ((tt==tn )||(tt==tn+1 ))
{ mode=6;
s=1;
}
if ((tt==tno)||(tt==tno+1 ))
{ mode=7;
s=1;
}
}
if(timer_1[timernumb][2]==1)//1-3 on off
{
tn=timer_1[timernumb][12]*100+timer_1[timernumb][13];
tno=timer_1[timernumb][14]*100+timer_1[timernumb][15];
if ((tt==tn )||(tt==tn+1 ))
{ mode=6;
s=1;
}
if ((tt==tno)||(tt==tno+1 ))
{ mode=7;
s=1;
}
}
}
}
//***************************************************************************************************************************

@ -0,0 +1,391 @@
void nigtset ()
{
boolean ret=0;
boolean ohl=1;
int cur=1;
int lamp=1;
int h1=0;
int m1=0;
int h2=0;
int m2=0;
int lux1=30;
int lux2=50;
int tcon=26;
int tdon=3;
int tcoff=25;
int tdoff=1;
second1=0;
boolean nighton=1;
digitalWrite(13, LOW);
//data**************DATA*********************************************************************************
data:
nighton=timernight[0];
h1=timernight[1];
m1=timernight[2];
h2=timernight[3];
m2=timernight[4];
lux1=timernight[5];
lux2=timernight[6];
ohl=timernight[7];
tcon=timernight[8];
tdon=timernight[9];
tcoff=timernight[10];
tdoff=timernight[11];
do {
//irem();
// button();
// delay (100);
second1++;
if (second1>1)
{ fl=!fl;
second1=0;
}
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, nightecr);
u8g.setColorIndex(0);
//u8g.setFont(u8g_font_04b_03br);//5x5
u8g.setFont(u8g_font_courR08);//7x5
// u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(68, 9);
u8g.print(nighton,DEC); //вкл режима ночь
u8g.setColorIndex(1);
u8g.setPrintPos(110, 40);
u8g.print(ohl,DEC); //вкл режима охлаждения
u8g.setPrintPos(24, 20); //vkl
if(h1<10){u8g.print("0");}
u8g.print(h1,DEC);
u8g.print(":");
if(m1<10){u8g.print("0");}
u8g.print(m1,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(84, 20); //vikl
if(h2<10){u8g.print("0");}
u8g.print(h2,DEC);
u8g.print(":");
if(m2<10){u8g.print("0");}
u8g.print(m2,DEC);
u8g.setFont(u8g_font_04b_03br);//5x5
if (lux1<10)
{u8g.setPrintPos(52, 28); //lux1
}
else
{u8g.setPrintPos(48, 28); //lux1
}
u8g.print(lux1,DEC);
l=lux1*26/100;
u8g.drawBox(20,24,l,3);
if (lux2<10)
{u8g.setPrintPos(52+66, 28); //lux2
}
else
{u8g.setPrintPos(46+66, 28); //lux2
}
u8g.print(lux2,DEC);
l=lux2*26/100;
u8g.drawBox(16+68,24,l,3);
u8g.setFont(u8g_font_courR08);//7x5
u8g.setPrintPos(24,52);
u8g.print(tcon,DEC); //t целая часть вкл охлаждения
u8g.print(",");
u8g.print(tdon,DEC);//t дробная часть вкл охлаждения
u8g.print(" C");
u8g.setFont(u8g_font_courR08);//7x5
u8g.setPrintPos(84,52);
u8g.print(tcoff,DEC); //t целая часть выкл охлаждения
u8g.print(",");
u8g.print(tdoff,DEC);//t дробная часть выкл охлаждения
u8g.print(" C");
if (cur==1)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(68,1,6,9);
if(fl==1){u8g.setColorIndex(0);}
if(fl==0){u8g.setColorIndex(1);}
u8g.setPrintPos(68, 9);
u8g.print(nighton,DEC); //вкл режима ночь
}
//*****************************vrem****************
if (cur==2){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,21,10,1);
}
if (cur==3){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(43,21,10,1);
}
if (cur==4){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(85,21,10,1);
}
if (cur==5){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(103,21,10,1);
}
//***********************************************
if (cur==6){//lux1
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(2,29,15,1);
}
//*********************** **********************
if (cur==7){//lux2
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(65,29,15,1);
}
//***********************************************
if (cur==8)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(110,32,6,9);
if(fl==1){u8g.setColorIndex(0);}
if(fl==0){u8g.setColorIndex(1);}
//u8g.setPrintPos(68, 9);
u8g.setPrintPos(110, 40);
u8g.print(ohl,DEC); //вкл режима охл
}
//*********************** **********************
if (cur==9){//tc on
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,53,10,1);
}
//*********************** **********************
if (cur==10){//td on
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(41,53,6,1);
}
//*********************** **********************
if (cur==11){//tc on
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25+60,53,11,1);
}
//*********************** **********************
if (cur==12){//td on
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(41+60,53,6,1);
}
u8g.setColorIndex(1);
} while( u8g.nextPage() );
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE908B15) //down
{ if(cur==1)
{
nighton=!nighton;
}
if(cur==2)
{h1=h1-1;
if(h1<0){h1=23;}
}
if(cur==3)
{m1=m1-1;
if(m1<0){m1=59;}
}
if(cur==4)
{h2=h2-1;
if(h2<0){h2=23;}
}
if(cur==5)
{m2=m2-1;
if(m2<0){m2=59;}
}
if(cur==6)
{lux1=lux1-1;
if(lux1<0){lux1=0;}
lamp=lux1*255/100;
analogWrite(7,lamp);
}
if(cur==7)
{lux2=lux2-1;
if(lux2<0){lux2=0;}
lamp=lux2*255/100;
analogWrite(7,lamp);
}
if(cur==8)
{
ohl=!ohl;
}
if(cur==9)
{tcon=tcon-1;
if(tcon<tcoff+1){tcon=tcoff+1;}
}
if(cur==10)
{tdon=tdon-1;
if(tdon<0){tdon=9;}
}
if(cur==11)
{tcoff=tcoff-1;
if(tcoff<20){tcoff=20;}
}
if(cur==12)
{tdoff=tdoff-1;
if(tdoff<0){tdoff=9;}
}
}
//*************************
if(results.value == 0xE900B95) //up E900B95
{ if(cur==1)
{
nighton=!nighton;
}
if(cur==2)
{h1=h1+1;
if(h1>23){h1=0;}
}
if(cur==3)
{m1=m1+1;
if(m1>59){m1=0;}
}
if(cur==4)
{h2=h2+1;
if(h2>23){h2=0;}
}
if(cur==5)
{m2=m2+1;
if(m2>59){m2=0;}
}
if(cur==6)
{lux1=lux1+1;
if(lux1>100){lux1=100;}
lamp=lux1*255/100;
analogWrite(7,lamp);
}
if(cur==7)
{lux2=lux2+1;
if(lux2>100){lux2=100;}
lamp=lux2*255/100;
analogWrite(7,lamp);
}
if(cur==8)
{
ohl=!ohl;
}
if(cur==9)
{tcon=tcon+1;
if(tcon>35){tcon=35;}
}
if(cur==10)
{tdon=tdon+1;
if(tdon>9){tdon=0;}
}
if(cur==11)
{tcoff=tcoff+1;
if(tcoff>tcon-1){tcoff=tcon-1;}
}
if(cur==12)
{tdoff=tdoff+1;
if(tdoff>9){tdoff=0;}
}
}
if(results.value == 0xE904BD5) //right E904BD5
{
cur=cur+1;
if (cur>12){cur=1;}
}
if(results.value == 0xE90CB55) //left E90CB55
{
cur=cur-1;
if (cur<1){cur=12;}
}
if(results.value == 0xE101A04) //enter E101A04
{int a=tyes();
if(a==1)
{timernight[0]=nighton;
timernight[1]=h1;
timernight[2]=m1;
timernight[3]=h2;
timernight[4]=m2;
timernight[5]=lux1;
timernight[6]=lux2;
timernight[7]=ohl;
timernight[8]=tcon;
timernight[9]=tdon;
timernight[10]=tcoff;
timernight[11]=tdoff;
savedatnight();
delay (500);
}
//lamp=l1*255/100;
//analogWrite(7,lamp);
nigts=0;
menu=0;
nagruz ();
ret=1;
} //выход с сохранением
if(results.value == 0xE106A74) //menu E106A74
{
nigts=0;
menu=0;
ret=1;
} //выход без сохранения
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
//**********************PDY********************
}while (ret<1);
}

@ -0,0 +1,68 @@
void radio()
{
int mode = digitalRead(42);
if (mode==LOW)
{
do {} while (!(nrf24l01p_get_irq_flags() & (1 << NRF24L01P_IRQ_RX_DR)));
//do {} while ((1 << NRF24L01P_IRQ_RX_DR));
nrf24l01p_clear_irq_flag(NRF24L01P_IRQ_RX_DR);
nrf24l01p_read_rx_payload((uint8_t*)payload);//, sizeof(payload));
rad=1;
}
else
{
rad=0;
}
}
//*****************************************************************
void peredat()
{
digitalWrite(45, LOW);//+5v nrf
delay (100);
data() ;
digitalWrite(45, HIGH);//+5v nrf
delay (100);
digitalWrite(NRF_CE_PIN, LOW);
uint8_t address[5] = { 0xE2, 0xE4, 0x23, 0xE4, 0x02 };
nrf_init(address);
static uint8_t payload1[NRF_PAYLOAD_LENGTH];
strcpy((char*)payload1, test_data);
nrf24l01p_write_tx_payload(payload1, sizeof(payload1));
digitalWrite(NRF_CE_PIN, HIGH);
delay(1);
digitalWrite(NRF_CE_PIN, LOW);
do {} while (!(nrf24l01p_get_irq_flags() & (1 << NRF24L01P_IRQ_TX_DS)));
nrf24l01p_clear_irq_flag(NRF24L01P_IRQ_TX_DS);
}
//*******************************************************************
void nrf_init(uint8_t *address)
{
delay(100);
nrf24l01p_get_clear_irq_flags();
nrf24l01p_close_pipe(NRF24L01P_ALL);
nrf24l01p_open_pipe(NRF24L01P_PIPE0, false);
nrf24l01p_set_crc_mode(NRF24L01P_CRC_16BIT);
nrf24l01p_set_address_width(NRF24L01P_AW_5BYTES);
nrf24l01p_set_address(NRF24L01P_PIPE0, address);
nrf24l01p_set_operation_mode(NRF24L01P_PRX);
nrf24l01p_set_rx_payload_width(NRF24L01P_PIPE0, NRF_PAYLOAD_LENGTH);
nrf24l01p_set_rf_channel(NRF_CHANNEL);
nrf24l01p_set_power_mode(NRF24L01P_PWR_UP);
delay(NRF_POWER_UP_DELAY);
}
void nrf24l01p_spi_ss(nrf24l01p_spi_ss_level_t level)
{
digitalWrite(SPI_SS_PIN, (level == NRF24L01P_SPI_SS_LOW ? LOW : HIGH));
}
uint8_t nrf24l01p_spi_rw(uint8_t value)
{
return SPI.transfer(value);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,315 @@
void settime ()
{boolean ret=0;
byte cur=1;
DateTime now = rtc.now();
//*********************************
hour1 = now.hour();
minute1 = now.minute();
second1 = now.second();
month1 =now.month();
day1= now.day();
year1 =now.year();
if (hour1>23){hour1=8;}
if (minute1>59){minute1=0;}
if (month1>12){month1=1;}
if (day1>31){day1=1;}
if (year1>2099){year1=2010;}
//****************************************
do {
//irem();
// button();
delay (200);
DateTime now = rtc.now();
second1 = now.second();
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, setmenu);
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(10, 28);
u8g.print(hour1/10,DEC);
u8g.print(hour1%10,DEC);
u8g.print(":");
u8g.print(minute1/10,DEC);
u8g.print(minute1%10,DEC);
u8g.print(":");
u8g.print(second1/10,DEC);
u8g.print(second1%10,DEC);
u8g.setPrintPos(8, 48);
u8g.print(day1/10,DEC);
u8g.print(day1%10,DEC);
u8g.print("/");
u8g.print(month1/10,DEC);
u8g.print(month1%10,DEC);
u8g.print("/");
u8g.print(year1,DEC);
if (cur==1){u8g.drawBox(10,30,16,1);}
if (cur==2){u8g.drawBox(34,30,16,1);}
if (cur==3){u8g.drawBox(8,50,16,1);}
if (cur==4){u8g.drawBox(32,50,16,1);}
if (cur==5){u8g.drawBox(56,50,32,1);}
if (cur==6){u8g.drawBox(58,30,16,1);}
} while( u8g.nextPage() );
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE908B15) //down
{ if(cur==1)
{ hour1=hour1-1;
if (hour1<0){hour1=23;}
}
if(cur==2)
{ minute1=minute1-1;
if (minute1<0){minute1=59;}
}
if(cur==3)
{ day1=day1-1;
if ((month1==1)||(month1==3)||(month1==5)||(month1==7)||(month1==8)||(month1==10)||(month1==12))
{if (day1<1){day1=31;}
}
if ((month1==4)||(month1==6)||(month1==9)||(month1==11))
{if (day1<1){day1=30;}
}
if (month1==2)
{if (day1<1){day1=29;}
}
}
if(cur==4)
{month1=month1-1;
if (month1<1){month1=12;}
}
if(cur==5)
{year1=year1-1;
if (year1<2010){year1=2099;}
}
if(cur==6)
{if (second1>35)
{if ( minute1==59)
{minute1=0;
hour1=hour1+1;
if (hour1>23){hour1=0;}
}
else
{ minute1=minute1+1;
}
}
second1=0;
rtc.adjust(DateTime(year1, month1, day1, hour1, minute1, second1));
}
}
if(results.value == 0xE900B95) //up E900B95
{
if(cur==1)
{ hour1=hour1+1;
if (hour1>23){hour1=0;}
}
if(cur==2)
{ minute1=minute1+1;
if (minute1>59){minute1=0;}
}
if(cur==3)
{ day1=day1+1;
if ((month1==1)||(month1==3)||(month1==5)||(month1==7)||(month1==8)||(month1==10)||(month1==12))
{if (day1>31){day1=1;}
}
if ((month1==4)||(month1==6)||(month1==9)||(month1==11))
{if (day1>30){day1=1;}
}
if (month1==2)
{if (day1>29){day1=1;}
}
}
if(cur==4)
{month1=month1+1;
if (month1>12){month1=1;}
}
if(cur==5)
{year1=year1+1;
if (year1>2099){year1=2010;}
}
if(cur==6)
{if (second1>35)
{if ( minute1==59)
{minute1=0;
hour1=hour1+1;
if (hour1>23){hour1=0;}
}
else
{ minute1=minute1+1;
}
}
second1=0;
rtc.adjust(DateTime(year1, month1, day1, hour1, minute1, second1));
}
}
if(results.value == 0xE101A04) //enter E101A04
{rtc.adjust(DateTime(year1, month1, day1, hour1, minute1, second1));
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
settim=0;
ret=1;
} //выход с сохранением
if(results.value == 0xE106A74) //menu E106A74
{
settim=0;
ret=1;
} //выход без сохранения
if(results.value == 0xE904BD5) //right E904BD5
{
cur=cur+1;
if (cur>6){cur=1;}
}
if(results.value == 0xE90CB55) //left E90CB55
{
cur=cur-1;
if (cur<1){cur=6;}
}
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
//**********************PDY********************
but ();
//***************************BUT*****************************************
if((b == 5)|| (b == 15))//down
{ if(cur==1)
{ hour1=hour1-1;
if (hour1<0){hour1=23;}
}
if(cur==2)
{ minute1=minute1-1;
if (minute1<0){minute1=59;}
}
if(cur==3)
{ day1=day1-1;
if ((month1==1)||(month1==3)||(month1==5)||(month1==7)||(month1==8)||(month1==10)||(month1==12))
{if (day1<1){day1=31;}
}
if ((month1==4)||(month1==6)||(month1==9)||(month1==11))
{if (day1<1){day1=30;}
}
if (month1==2)
{if (day1<1){day1=29;}
}
}
if(cur==4)
{month1=month1-1;
if (month1<1){month1=12;}
}
if(cur==5)
{year1=year1-1;
if (year1<2010){year1=2099;}
}
if(cur==6)
{if (second1>35)
{if ( minute1==59)
{minute1=0;
hour1=hour1+1;
if (hour1>23){hour1=0;}
}
else
{ minute1=minute1+1;
}
}
second1=0;
rtc.adjust(DateTime(year1, month1, day1, hour1, minute1, second1));
}
}
if((b == 4)|| (b == 14)) //up E900B95
{
if(cur==1)
{ hour1=hour1+1;
if (hour1>23){hour1=0;}
}
if(cur==2)
{ minute1=minute1+1;
if (minute1>59){minute1=0;}
}
if(cur==3)
{ day1=day1+1;
if ((month1==1)||(month1==3)||(month1==5)||(month1==7)||(month1==8)||(month1==10)||(month1==12))
{if (day1>31){day1=1;}
}
if ((month1==4)||(month1==6)||(month1==9)||(month1==11))
{if (day1>30){day1=1;}
}
if (month1==2)
{if (day1>29){day1=1;}
}
}
if(cur==4)
{month1=month1+1;
if (month1>12){month1=1;}
}
if(cur==5)
{year1=year1+1;
if (year1>2099){year1=2010;}
}
if(cur==6)
{if (second1>35)
{if ( minute1==59)
{minute1=0;
hour1=hour1+1;
if (hour1>23){hour1=0;}
}
else
{ minute1=minute1+1;
}
}
second1=0;
rtc.adjust(DateTime(year1, month1, day1, hour1, minute1, second1));
}
}
if((b == 3)|| (b == 13)) //enter E101A04
{rtc.adjust(DateTime(year1, month1, day1, hour1, minute1, second1));
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
settim=0;
ret=1;
} //выход с сохранением
if((b == 1)|| (b == 11)) //menu E106A74
{
settim=0;
ret=1;
} //выход без сохранения
if((b == 6)|| (b == 16)) //right E904BD5
{
cur=cur+1;
if (cur>6){cur=1;}
}
if((b == 2)|| (b == 12)) //left E90CB55
{
cur=cur-1;
if (cur<1){cur=6;}
}
//***************************BUT*****************************************
}while (ret<1);
}

@ -0,0 +1,358 @@
void temperat1()
{
OneWire ds(22);
ds.reset();
ds.write(0xCC);
ds.write(0x4E);
ds.write(0x7D);
ds.write(0xFC);
ds.write(0x7F);//точность изм от нее зависит скорость опроса tconvert=750 мс/(2**(3-R))
ds.reset();
ds.write(0xCC);
ds.write(0x44);
}
void temperat11()
{ OneWire ds(22);
byte data[2];
byte zn=0;
ds.reset();
ds.write(0xCC);
ds.write(0xBE);
data[0] = ds.read();
data[1] = ds.read();
//Serial.print("data[0]=");
//Serial.println(data[0],BIN);
//Serial.print("data[1]=");
//Serial.println(data[1],BIN);
if ((data[1]&128) == 0)
{zn=1; //+
}
else{
zn=0; //-
}
if (zn==0)//преобразуем отр темп
{
unsigned int tmp;
// «склеиваем» нулевой и первый байты ОЗУ датчика
tmp = ((unsigned int)data[1]<<8)|data[0];
//выполняем операцию логического отрицания
tmp = ~tmp + 1;// (-0,5) 1111 1111 1111 1000=~ 1111 1111 1111 1000= 0000 0000 0000 0111+1= 0000 0000 0000 1000
//помещаем результат в соответствующие переменные
data[0] = tmp; //0000 1000
data[1] = tmp>>8; //0000 0000
}
int Temp = (data[1]<< 8)+data[0];
//Serial.print("Temp=");
//Serial.println(Temp,BIN);
//выделяем с помощью битовой маски дробную часть
byte temperature = (data[0]&15);//1101 1000 & 0000 1111= 0000 1000 (8)
// Serial.print("temppointbin=");
//Serial.println(temperature,BIN);
//преобразуем в целое число
temperature = (temperature<<1) + (temperature<<3);// Умножаем на 10 (80) 0000 1000<<1= 0001 0000 + 0000 1000<<3=0100 000 = 0101 0000 (80)
temperature = (temperature>>4);//делим на 16 или умножаем на 0.0625 (5) 0101 0000>>4=0000 0101 (5)
td1=temperature;
//Serial.print("temppoint=");//дробная часть
//Serial.println(temperature);
tc1 = Temp>>4;//целая часть
if(tc1==0){tc1=24;}
//Serial.print("Temp>>4=");
//Serial.println(Temp,BIN);
//Serial.println(Temp);
int tem1=tc1*10+td1;//вводим кор коэф +0,7 С
tem1=tem1+(tc11*10+td11);
tc1=tem1/10;//*****************!!!!!!!!!!!! из-за ошибки датчика
td1=tem1%10;
}
void temperat2()
{
OneWire ds(24);
ds.reset();
ds.write(0xCC);
ds.write(0x44);
}
void temperat22()
{ OneWire ds(24);
byte data[2];
byte zn=0;
ds.reset();
ds.write(0xCC);
ds.write(0xBE);
data[0] = ds.read();
data[1] = ds.read();
//Serial.print("data[0]=");
//Serial.println(data[0],BIN);
//Serial.print("data[1]=");
//Serial.println(data[1],BIN);
if ((data[1]&128) == 0)
{zn=1; //+
}
else{
zn=0; //-
}
if (zn==0)//преобразуем отр темп
{
unsigned int tmp;
// «склеиваем» нулевой и первый байты ОЗУ датчика
tmp = ((unsigned int)data[1]<<8)|data[0];
//выполняем операцию логического отрицания
tmp = ~tmp + 1;// (-0,5) 1111 1111 1111 1000=~ 1111 1111 1111 1000= 0000 0000 0000 0111+1= 0000 0000 0000 1000
//помещаем результат в соответствующие переменные
data[0] = tmp; //0000 1000
data[1] = tmp>>8; //0000 0000
}
int Temp = (data[1]<< 8)+data[0];
//Serial.print("Temp=");
//Serial.println(Temp,BIN);
//выделяем с помощью битовой маски дробную часть
byte temperature = (data[0]&15);//1101 1000 & 0000 1111= 0000 1000 (8)
// Serial.print("temppointbin=");
//Serial.println(temperature,BIN);
//преобразуем в целое число
temperature = (temperature<<1) + (temperature<<3);// Умножаем на 10 (80) 0000 1000<<1= 0001 0000 + 0000 1000<<3=0100 000 = 0101 0000 (80)
temperature = (temperature>>4);//делим на 16 или умножаем на 0.0625 (5) 0101 0000>>4=0000 0101 (5)
td2=temperature;
//Serial.print("temppoint=");//дробная часть
//Serial.println(temperature);
tc2 = Temp>>4;//целая часть
//Serial.print("Temp>>4=");
//Serial.println(Temp,BIN);
//Serial.println(Temp);
int tem2=tc2*10+td2;//вводим кор коэф -0,7 С
tem2=tem2-(tc22*10+td22);
tc2=tem2/10;
td2=tem2%10;
}
void temperat3()
{
OneWire ds(26);
ds.reset();
ds.write(0xCC);
ds.write(0x44);
}
void temperat33()
{ OneWire ds(26);
byte data[2];
byte zn=0;
ds.reset();
ds.write(0xCC);
ds.write(0xBE);
data[0] = ds.read();
data[1] = ds.read();
//Serial.print("data[0]=");
//Serial.println(data[0],BIN);
//Serial.print("data[1]=");
//Serial.println(data[1],BIN);
if ((data[1]&128) == 0)
{zn=1; //+
}
else{
zn=0; //-
}
if (zn==0)//преобразуем отр темп
{
unsigned int tmp;
// «склеиваем» нулевой и первый байты ОЗУ датчика
tmp = ((unsigned int)data[1]<<8)|data[0];
//выполняем операцию логического отрицания
tmp = ~tmp + 1;// (-0,5) 1111 1111 1111 1000=~ 1111 1111 1111 1000= 0000 0000 0000 0111+1= 0000 0000 0000 1000
//помещаем результат в соответствующие переменные
data[0] = tmp; //0000 1000
data[1] = tmp>>8; //0000 0000
}
int Temp = (data[1]<< 8)+data[0];
//Serial.print("Temp=");
//Serial.println(Temp,BIN);
//выделяем с помощью битовой маски дробную часть
byte temperature = (data[0]&15);//1101 1000 & 0000 1111= 0000 1000 (8)
// Serial.print("temppointbin=");
//Serial.println(temperature,BIN);
//преобразуем в целое число
temperature = (temperature<<1) + (temperature<<3);// Умножаем на 10 (80) 0000 1000<<1= 0001 0000 + 0000 1000<<3=0100 000 = 0101 0000 (80)
temperature = (temperature>>4);//делим на 16 или умножаем на 0.0625 (5) 0101 0000>>4=0000 0101 (5)
td3=temperature;
//Serial.print("temppoint=");//дробная часть
//Serial.println(temperature);
tc3 = Temp>>4;//целая часть
//Serial.print("Temp>>4=");
//Serial.println(Temp,BIN);
//Serial.println(Temp);
int tem3=tc3*10+td3;//вводим кор коэф +0,7 С( tc33,td33 C)
tem3=tem3+(tc33*10+td33);
tc3=tem3/10;
td3=tem3%10;
}
void tempoff1()
{
if (timernight[7]==1)//проверка вкл режима охлаждения 1-вкл 0-выкл
{
if (tc1==timernight[8])
{
if (td1>timernight[9])
{
if(n5==0){digitalWrite(6, HIGH);}
digitalWrite(9, HIGH); // включает вентилятор
// digitalWrite(10, HIGH); // включает вентилятор
//digitalWrite(11, HIGH); // включает вентилятор
vent=1;
n5=1;
}
}
if (tc1>timernight[8])
{
if(n5==0){digitalWrite(6, HIGH);}
n5=1;
digitalWrite(9, HIGH); // включает вентилятор
//digitalWrite(10, HIGH); // включает вентилятор
//digitalWrite(11, HIGH); // включает вентилятор
vent=1;
}
if (tc1==timernight[10])
{
if (td1<timernight[11])
{
if(n5==0){digitalWrite(6, LOW);}
digitalWrite(9, LOW); // выключает вентилятор
vent=0;
}
}
if (tc1<timernight[10])
{
if(n5==0){digitalWrite(6, LOW); }
digitalWrite(9, LOW); // выключает вентилятор
vent=0;
}
//*************************ВЕНТ-2*************************
if (tc2==timernight[8])
{
if (td2>timernight[9])
{
if(n5==0){digitalWrite(6, HIGH);}
//digitalWrite(9, HIGH); // включает вентилятор
digitalWrite(10, HIGH); // включает вентилятор
//digitalWrite(11, HIGH); // включает вентилятор
vent=1;
n5=1;
}
}
if (tc2>timernight[8])
{
if(n5==0){digitalWrite(6, HIGH);}
n5=1;
//digitalWrite(9, HIGH); // включает вентилятор
digitalWrite(10, HIGH); // включает вентилятор
//digitalWrite(11, HIGH); // включает вентилятор
vent=1;
}
if (tc2==timernight[10])
{
if (td2<timernight[11])
{
if(n5==0){digitalWrite(6, LOW);}
digitalWrite(10, LOW); // выключает вентилятор
vent=0;
}
}
if (tc2<timernight[10])
{
if(n5==0){digitalWrite(6, LOW); }
digitalWrite(10, LOW); // выключает вентилятор
vent=0;
}
}
}
void tempoff3()
{
if (timernight[7]==1)//проверка вкл режима охлаждения 1-вкл 0-выкл
{
if (tc3==timernight[8])
{
if (td3>timernight[9])
{
if(n5==0){digitalWrite(6, HIGH);}
//digitalWrite(9, HIGH); // включает вентилятор
//digitalWrite(10, HIGH); // включает вентилятор
digitalWrite(11, HIGH); // включает вентилятор
vent=1;
n5=1;
}
}
if (tc3>timernight[8])
{
if(n5==0){digitalWrite(6, HIGH);}
n5=1;
//digitalWrite(9, HIGH); // включает вентилятор
//digitalWrite(10, HIGH); // включает вентилятор
digitalWrite(11, HIGH); // включает вентилятор
vent=1;
}
if (tc3==timernight[10])
{
if (td3<timernight[11])
{
if(n5==0){digitalWrite(6, LOW);}
digitalWrite(11, LOW); // выключает вентилятор
vent=0;
}
}
if (tc3<timernight[10])
{
if(n5==0){digitalWrite(6, LOW); }
digitalWrite(11, LOW); // выключает вентилятор
vent=0;
}
}
}

@ -0,0 +1,288 @@
void timer1 ()
{boolean ret=0;
byte cur=1;
//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;// budilnik
//****************************************
do {
//irem();
// button();
delay (200);
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, bud1);
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(13, 23);
u8g.print(hourt1/10,DEC);
u8g.print(hourt1%10,DEC);
u8g.print(":");
u8g.print(mint1/10,DEC);
u8g.print(mint1%10,DEC);
if (on==0)
{u8g.drawXBMP(58, 12, 16, 12, budoff);
}
else
{u8g.drawXBMP(58, 12, 16, 12, budon);
}
if (bod==0)
{u8g.drawXBMP(76, 12, 16, 12, sev);
}
else
{u8g.drawXBMP(76, 12, 16, 12, od);
}
int vol1=38-((90-52)*note/255);
// int vol1=((90-52)*note/255);
u8g.drawFrame(52,46,38,4);
u8g.drawBox(52,46,vol1,4);
if (pn==1){u8g.drawBox(6,37,10,1);}
if (vt==1){u8g.drawBox(19,37,8,1);}
if (sr==1){u8g.drawBox(30,37,10,1);}
if (cht==1){u8g.drawBox(43,37,8,1);}
if (pt==1){u8g.drawBox(54,37,8,1);}
if (sb==1){u8g.drawBox(65,37,10,1);}
if (vs==1){u8g.drawBox(78,37,10,1);}
if (cur==1){u8g.drawBox(13,24,16,1);}
if (cur==2){u8g.drawBox(37,24,16,1);}
if (cur==3){u8g.drawBox(58,24,14,1);}
if (cur==4){u8g.drawBox(78,24,12,1);}
if (cur==5){u8g.drawBox(6,39,10,1);}
if (cur==6){u8g.drawBox(19,39,8,1);}
if (cur==7){u8g.drawBox(30,39,10,1);}
if (cur==8){u8g.drawBox(43,39,8,1);}
if (cur==9){u8g.drawBox(54,39,8,1);}
if (cur==10){u8g.drawBox(65,39,10,1);}
if (cur==11){u8g.drawBox(78,39,10,1);}
if (cur==12){u8g.drawBox(2,52,47,1);}
} while( u8g.nextPage() );
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE908B15) //down
{ if(cur==1)
{ hourt1=hourt1-1;
if (hourt1<0){hourt1=23;}
}
if(cur==2)
{ mint1=mint1-1;
if (mint1<0){mint1=59;}
}
if(cur==3)
{
if (on==1)
{on=0;
}
else{on=1;
}
}
if(cur==4)
{
if (bod==1)
{bod=0;
}
else{bod=1;
}
}
if(cur==5)//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;// budilnik
{ if (pn==1)
{pn=0;
}
else{pn=1;
}
}
if(cur==6)
{ if (vt==1)
{vt=0;
}
else{vt=1;
}
}
if(cur==7)
{ if (sr==1)
{sr=0;
}
else{sr=1;
}
}
if(cur==8)
{ if (cht==1)
{cht=0;
}
else{cht=1;
}
}
if(cur==9)
{ if (pt==1)
{pt=0;
}
else{pt=1;
}
}
if(cur==10)
{ if (sb==1)
{sb=0;
}
else{sb=1;
}
}
if(cur==11)
{ if (vs==1)
{vs=0;
}
else{vs=1;
}
}
if(cur==12)
{note=note+10;
if(note>254){note=254;}
}
}
if(results.value == 0xE900B95) //up E900B95
{ if(cur==1)
{ hourt1=hourt1+1;
if (hourt1>23){hourt1=0;}
}
if(cur==2)
{ mint1=mint1+1;
if (mint1>59){mint1=0;}
}
if(cur==3)
{
if (on==1)
{on=0;
}
else{on=1;
}
}
if(cur==4)
{
if (bod==1)
{bod=0;
}
else{bod=1;
}
}
if(cur==5)//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;// budilnik
{ if (pn==1)
{pn=0;
}
else{pn=1;
}
}
if(cur==6)
{ if (vt==1)
{vt=0;
}
else{vt=1;
}
}
if(cur==7)
{ if (sr==1)
{sr=0;
}
else{sr=1;
}
}
if(cur==8)
{ if (cht==1)
{cht=0;
}
else{cht=1;
}
}
if(cur==9)
{ if (pt==1)
{pt=0;
}
else{pt=1;
}
}
if(cur==10)
{ if (sb==1)
{sb=0;
}
else{sb=1;
}
}
if(cur==11)
{ if (vs==1)
{vs=0;
}
else{vs=1;
}
}
if(cur==12)
{note=note-10;
if(note<5){note=5;}
}
}
if(results.value == 0xE101A04) //enter E101A04
{ustt1=0;
ret=1;
} //выход с сохранением
if(results.value == 0xE106A74) //menu E106A74
{ ustt1=0;
ret=1;
} //выход без сохранения
if(results.value == 0xE904BD5) //right E904BD5
{
cur=cur+1;
if (cur>12){cur=1;}
}
if(results.value == 0xE90CB55) //left E90CB55
{
cur=cur-1;
if (cur<1){cur=12;}
}
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
}while (ret<1);
delay(300);
}

@ -0,0 +1,688 @@
void timerset ()
{
boolean ret=0;
int cur=1;
int ntimold=ntim;
int tu;
int td;
int tv;
int h1;
int m1;
int h2;
int m2;
int h3;
int m3;
int h4;
int m4;
int h5;
int m5;
int h6;
int m6;
int kan;
second1=0;
//secold=now.second();
//data**************DATA*********************************************************************************
data:
tu=timer_1[ntim-1][0];
td=timer_1[ntim-1][1];
tv=timer_1[ntim-1][2];
kan=timer_1[ntim-1][3];
h1=timer_1[ntim-1][4];
m1=timer_1[ntim-1][5];
h2=timer_1[ntim-1][6];
m2=timer_1[ntim-1][7];
h3=timer_1[ntim-1][8];
m3=timer_1[ntim-1][9];
h4=timer_1[ntim-1][10];
m4=timer_1[ntim-1][11];
h5=timer_1[ntim-1][12];
m5=timer_1[ntim-1][13];
h6=timer_1[ntim-1][14];
m6=timer_1[ntim-1][15];
pn=timer_1[ntim-1][16];
vt=timer_1[ntim-1][17];
sr=timer_1[ntim-1][18];
cht=timer_1[ntim-1][19];
pt=timer_1[ntim-1][20];
sb=timer_1[ntim-1][21];
vs=timer_1[ntim-1][22];
//**************************DO***************************************************************************
do {
//irem();
// button();
delay (100);
second1++;
if (second1>1)
{ fl=!fl;
second1=0;
}
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.drawXBMP(0, 0, 128, 64, timer);
// u8g.setColorIndex(0);
//u8g.setFont(u8g_font_04b_03br);//5x5
u8g.setFont(u8g_font_courR08);//7x5
// u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(50, 9);
u8g.print(ntim,DEC); //nomer timera
// u8g.print(".");
u8g.setColorIndex(0);
u8g.setPrintPos(112, 9); //nomer kanala nagruzki
u8g.print(kan,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(24, 32); //vkl
if(h1<10){u8g.print("0");}
u8g.print(h1,DEC);
u8g.print(":");
if(m1<10){u8g.print("0");}
u8g.print(m1,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(84, 32); //vikl
if(h2<10){u8g.print("0");}
u8g.print(h2,DEC);
u8g.print(":");
if(m2<10){u8g.print("0");}
u8g.print(m2,DEC);
u8g.setPrintPos(24, 43); //vk2
if(h3<10){u8g.print("0");}
u8g.print(h3,DEC);
u8g.print(":");
if(m3<10){u8g.print("0");}
u8g.print(m3,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(84, 43); //vik2
if(h4<10){u8g.print("0");}
u8g.print(h4,DEC);
u8g.print(":");
if(m4<10){u8g.print("0");}
u8g.print(m4,DEC);
u8g.setPrintPos(24, 54); //vk3
if(h5<10){u8g.print("0");}
u8g.print(h5,DEC);
u8g.print(":");
if(m5<10){u8g.print("0");}
u8g.print(m5,DEC);
u8g.setColorIndex(1);
u8g.setPrintPos(84, 54); //vik3
if(h6<10){u8g.print("0");}
u8g.print(h6,DEC);
u8g.print(":");
if(m6<10){u8g.print("0");}
u8g.print(m6,DEC);
if(pn==1){u8g.drawBox(10,20,11,1);}
if(vt==1){u8g.drawBox(26,20,11,1);}
if(sr==1){u8g.drawBox(42,20,11,1);}
if(cht==1){u8g.drawBox(57,20,12,1);}
if(pt==1){u8g.drawBox(73,20,12,1);}
if(sb==1){u8g.drawBox(89,20,12,1);}
if(vs==1){u8g.drawBox(105,20,12,1);}
if(tu==0)
{ //u8g.setPrintPos(2, 32);// t1.1
u8g.setColorIndex(0);
u8g.drawBox(2,23,124,9);
u8g.setColorIndex(1);
u8g.setPrintPos(3, 32);// t1.1
u8g.print("OFF");
}
if(td==0)
{
u8g.setColorIndex(0);
u8g.drawBox(2,34,124,9);
u8g.setColorIndex(1);
u8g.setPrintPos(3, 43);// t1.1
u8g.print("OFF");
}
if(tv==0)
{ //u8g.setPrintPos(2, 54);// t1.1
u8g.setColorIndex(0);
u8g.drawBox(2,45,124,9);
u8g.setColorIndex(1);
u8g.setPrintPos(3, 54);// t1.1
u8g.print("OFF");
}
if (cur==1)
{
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(50,1,6,9);
if(fl==1){u8g.setColorIndex(0);}
if(fl==0){u8g.setColorIndex(1);}
u8g.setPrintPos(50, 9);
u8g.print(ntim,DEC); //nomer timera
}
if (cur==2)
{if(fl==1){u8g.setColorIndex(0);}
if(fl==0){u8g.setColorIndex(1);}
u8g.drawBox(112,1,6,9);
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.setPrintPos(112, 9); //nomer kanala nagruzki
u8g.print(kan,DEC);
}
if (cur==3){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(10,22,11,1);
}
if (cur==4){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(26,22,11,1);
}
if (cur==5){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(42,22,11,1);
}
if (cur==6){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(57,22,12,1);
}
if (cur==7){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(73,22,12,1);
}
if (cur==8){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(89,22,12,1);
}
if (cur==9){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(105,22,12,1);
}
//*************************************************
if (cur==10){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
if(tu==0)
{u8g.drawBox(3,33,18,1);
}
else
{u8g.drawBox(3,33,5,1);}
}
//*****************************vrem****************
if (cur==11){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,33,10,1);
}
if (cur==12){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(43,33,10,1);
}
if (cur==13){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(85,33,10,1);
}
if (cur==14){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(103,33,10,1);
}
//***********************************************
if (cur==15){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
if(td==0)
{u8g.drawBox(3,44,18,1);;
}
else
{u8g.drawBox(3,44,5,1);}
}
//*********************** **********************
if (cur==16){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,44,10,1);
}
if (cur==17){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(43,44,10,1);
}
if (cur==18){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(85,44,10,1);
}
if (cur==19){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(103,44,10,1);
}
//***********************************************
if (cur==20){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
if(tv==0)
{u8g.drawBox(3,55,18,1);;
}
else
{u8g.drawBox(3,55,5,1);}
}
//*********************** **********************
if (cur==21){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(25,55,10,1);
}
if (cur==22){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(43,55,10,1);
}
if (cur==23){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(85,55,10,1);
}
if (cur==24){
if(fl==0){u8g.setColorIndex(0);}
if(fl==1){u8g.setColorIndex(1);}
u8g.drawBox(103,55,10,1);
}
u8g.setColorIndex(1);
} while( u8g.nextPage() );
//**********************PDY********************
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
digitalWrite(13, HIGH);
if(results.value == 0xE908B15) //down
{ if(cur==1)
{ ntim=ntim-1;
if (ntim<1){ntim=1;}
}
if(cur==2)
{ kan=kan-1;
if (kan<1){kan=1;}
}
if(cur==3)//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;// budilnik
{ if (pn==1)
{pn=0;
}
else{pn=1;
}
}
if(cur==4)
{ if (vt==1)
{vt=0;
}
else{vt=1;
}
}
if(cur==5)
{ if (sr==1)
{sr=0;
}
else{sr=1;
}
}
if(cur==6)
{ if (cht==1)
{cht=0;
}
else{cht=1;
}
}
if(cur==7)
{ if (pt==1)
{pt=0;
}
else{pt=1;
}
}
if(cur==8)
{ if (sb==1)
{sb=0;
}
else{sb=1;
}
}
if(cur==9)
{ if (vs==1)
{vs=0;
}
else{vs=1;
}
}
if(cur==10)
{tu=!tu;
}
if(cur==11)
{h1=h1-1;
if(h1<0){h1=23;}
}
if(cur==12)
{m1=m1-1;
if(m1<0){m1=59;}
}
if(cur==13)
{h2=h2-1;
if(h2<0){h2=23;}
}
if(cur==14)
{m2=m2-1;
if(m2<0){m2=59;}
}
if(cur==15)
{td=!td;
}
if(cur==16)
{h3=h3-1;
if(h3<0){h3=23;}
}
if(cur==17)
{m3=m3-1;
if(m3<0){m3=59;}
}
if(cur==18)
{h4=h4-1;
if(h4<0){h4=23;}
}
if(cur==19)
{m4=m4-1;
if(m4<0){m4=59;}
}
if(cur==20)
{tv=!tv;
}
if(cur==21)
{h5=h5-1;
if(h5<0){h5=23;}
}
if(cur==22)
{m5=m5-1;
if(m5<0){m5=59;}
}
if(cur==23)
{h6=h6-1;
if(h6<0){h6=23;}
}
if(cur==24)
{m6=m6-1;
if(m6<0){m6=59;}
}
}
//*************************
if(results.value == 0xE900B95) //up E900B95
{ if(cur==1)
{ ntim=ntim+1;
if (ntim>6){ntim=6;}
}
if(cur==2)
{ kan=kan+1;
if (kan>5){kan=5;}
}
if(cur==3)//boolean pn,vt,sr,cht,pt,sb,vs,on,bod;
{ if (pn==1)
{pn=0;
}
else{pn=1;
}
}
if(cur==4)
{ if (vt==1)
{vt=0;
}
else{vt=1;
}
}
if(cur==5)
{ if (sr==1)
{sr=0;
}
else{sr=1;
}
}
if(cur==6)
{ if (cht==1)
{cht=0;
}
else{cht=1;
}
}
if(cur==7)
{ if (pt==1)
{pt=0;
}
else{pt=1;
}
}
if(cur==8)
{ if (sb==1)
{sb=0;
}
else{sb=1;
}
}
if(cur==9)
{ if (vs==1)
{vs=0;
}
else{vs=1;
}
}
if(cur==10)
{tu=!tu;
}
if(cur==11)
{h1=h1+1;
if(h1>23){h1=0;}
}
if(cur==12)
{m1=m1+1;
if(m1>59){m1=0;}
}
if(cur==13)
{h2=h2+1;
if(h2>23){h2=0;}
}
if(cur==14)
{m2=m2+1;
if(m2>59){m2=0;}
}
if(cur==15)
{td=!td;
}
if(cur==16)
{h3=h3+1;
if(h3>23){h3=0;}
}
if(cur==17)
{m3=m3+1;
if(m3>59){m3=0;}
}
if(cur==18)
{h4=h4+1;
if(h4>23){h4=0;}
}
if(cur==19)
{m4=m4+1;
if(m4>59){m4=0;}
}
if(cur==20)
{tv=!tv;
}
if(cur==21)
{h5=h5+1;
if(h5>23){h5=0;}
}
if(cur==22)
{m5=m5+1;
if(m5>59){m5=0;}
}
if(cur==23)
{h6=h6+1;
if(h6>23){h6=0;}
}
if(cur==24)
{m6=m6+1;
if(m6>59){m6=0;}
}
}
if(results.value == 0xE904BD5) //right E904BD5
{
cur=cur+1;
if (cur==11)
{if (tu==0){cur=15;}
}
if (cur==16)
{if (td==0){cur=20;}
}
if (cur==21)
{if (tv==0){cur=25;}
}
if (cur>24){cur=1;}
}
if(results.value == 0xE90CB55) //left E90CB55
{
cur=cur-1;
if (cur==14)
{if (tu==0){cur=10;}
}
if (cur==19)
{if (td==0){cur=15;}
}
if (cur<1){cur=24;}
if (cur==24)
{if (tv==0){cur=20;}
}
}
if(results.value == 0xE101A04) //enter E101A04
{int a=tyes();
if(a==1)
{timer_1[ntim-1][0]=tu;
timer_1[ntim-1][1]=td;
timer_1[ntim-1][2]=tv;
timer_1[ntim-1][3]=kan;
timer_1[ntim-1][4]=h1;
timer_1[ntim-1][5]=m1;
timer_1[ntim-1][6]=h2;
timer_1[ntim-1][7]=m2;
timer_1[ntim-1][8]=h3;
timer_1[ntim-1][9]=m3;
timer_1[ntim-1][10]=h4;
timer_1[ntim-1][11]=m4;
timer_1[ntim-1][12]=h5;
timer_1[ntim-1][13]=m5;
timer_1[ntim-1][14]=h6;
timer_1[ntim-1][15]=m6;
timer_1[ntim-1][16]=pn;
timer_1[ntim-1][17]=vt;
timer_1[ntim-1][18]=sr;
timer_1[ntim-1][19]=cht;
timer_1[ntim-1][20]=pt;
timer_1[ntim-1][21]=sb;
timer_1[ntim-1][22]=vs;
savedat();
nagruz ();
}
settimer=0;
ret=1;
} //выход с сохранением
if(results.value == 0xE106A74) //menu E106A74
{ /* int a=tyes();
if(a==1)
{
timer_1[ntim-1][0]=tu;
timer_1[ntim-1][1]=td;
timer_1[ntim-1][2]=tv;
timer_1[ntim-1][3]=kan;
timer_1[ntim-1][4]=h1;
timer_1[ntim-1][5]=m1;
timer_1[ntim-1][6]=h2;
timer_1[ntim-1][7]=m2;
timer_1[ntim-1][8]=h3;
timer_1[ntim-1][9]=m3;
timer_1[ntim-1][10]=h4;
timer_1[ntim-1][11]=m4;
timer_1[ntim-1][12]=h5;
timer_1[ntim-1][13]=m5;
timer_1[ntim-1][14]=h6;
timer_1[ntim-1][15]=m6;
timer_1[ntim-1][16]=pn;
timer_1[ntim-1][17]=vt;
timer_1[ntim-1][18]=sr;
timer_1[ntim-1][19]=cht;
timer_1[ntim-1][20]=pt;
timer_1[ntim-1][21]=sb;
timer_1[ntim-1][22]=vs;
//savedat();
}*/
settimer=0;
ret=1;
} //выход без сохранения
delay (100);
irrecv.resume(); // Receive the next value
digitalWrite(13, LOW);
}//ir
//**********************PDY********************
but();
if((b == 1)|| (b == 11)) //menu E106A74
{
settimer=0;
ret=1;
} //выход без сохранения
if(ntim!=ntimold)
{
ntimold=ntim ;
goto data;
}
digitalWrite(13, LOW);
}while (ret<1);
delay(300);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,177 @@
/*
u8g_bitmap.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap)
{
while( cnt > 0 )
{
u8g_Draw8Pixel(u8g, x, y, 0, *bitmap);
bitmap++;
cnt--;
x+=8;
}
}
void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap)
{
if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 )
return;
while( h > 0 )
{
u8g_DrawHBitmap(u8g, x, y, cnt, bitmap);
bitmap += cnt;
y++;
h--;
}
}
void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap)
{
while( cnt > 0 )
{
u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap));
bitmap++;
cnt--;
x+=8;
}
}
void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
{
if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 )
return;
while( h > 0 )
{
u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap);
bitmap += cnt;
y++;
h--;
}
}
/*=========================================================================*/
static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap)
{
uint8_t d;
x+=7;
while( w >= 8 )
{
u8g_Draw8Pixel(u8g, x, y, 2, *bitmap);
bitmap++;
w-= 8;
x+=8;
}
if ( w > 0 )
{
d = *bitmap;
x -= 7;
do
{
if ( d & 1 )
u8g_DrawPixel(u8g, x, y);
x++;
w--;
d >>= 1;
} while ( w > 0 );
}
}
void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap)
{
u8g_uint_t b;
b = w;
b += 7;
b >>= 3;
if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
return;
while( h > 0 )
{
u8g_DrawHXBM(u8g, x, y, w, bitmap);
bitmap += b;
y++;
h--;
}
}
static void u8g_DrawHXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const u8g_pgm_uint8_t *bitmap)
{
uint8_t d;
x+=7;
while( w >= 8 )
{
u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap));
bitmap++;
w-= 8;
x+=8;
}
if ( w > 0 )
{
d = u8g_pgm_read(bitmap);
x -= 7;
do
{
if ( d & 1 )
u8g_DrawPixel(u8g, x, y);
x++;
w--;
d >>= 1;
} while ( w > 0 );
}
}
void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
{
u8g_uint_t b;
b = w;
b += 7;
b >>= 3;
if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
return;
while( h > 0 )
{
u8g_DrawHXBMP(u8g, x, y, w, bitmap);
bitmap += b;
y++;
h--;
}
}

@ -0,0 +1,382 @@
/*
u8g_circle.c
Utility to draw empty and filled circles.
Universal 8bit Graphics Library
Copyright (c) 2011, bjthom@gmail.com
u8g_DrawCircle & u8g_DrawDisc by olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Addition to the U8G Library 02/25/12
*/
#include "u8g.h"
#ifdef OLD_CODE
void circ_upperRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
u8g_DrawPixel(u8g, x0 + x, y0 - y);
u8g_DrawPixel(u8g, x0 + y, y0 - x);
}
void circ_upperLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
u8g_DrawPixel(u8g, x0 - x, y0 - y);
u8g_DrawPixel(u8g, x0 - y, y0 - x);
}
void circ_lowerRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
u8g_DrawPixel(u8g, x0 + x, y0 + y);
u8g_DrawPixel(u8g, x0 + y, y0 + x);
}
void circ_lowerLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
u8g_DrawPixel(u8g, x0 - x, y0 + y);
u8g_DrawPixel(u8g, x0 - y, y0 + x);
}
void circ_all(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
circ_upperRight(u8g, x, y, x0, y0);
circ_upperLeft(u8g, x, y, x0, y0);
circ_lowerRight(u8g, x, y, x0, y0);
circ_lowerLeft(u8g, x, y, x0, y0);
}
void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
{
if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
return;
int f = 1 - rad;
int ddF_x = 1;
int ddF_y = -2*rad;
uint8_t x = 0;
uint8_t y = rad;
void ( *circ_util )(u8g_t *, u8g_uint_t, u8g_uint_t, u8g_uint_t, u8g_uint_t);
switch (option)
{
case U8G_CIRC_UPPER_RIGHT:
u8g_DrawPixel(u8g, x0, y0 - rad);
u8g_DrawPixel(u8g, x0 + rad, y0);
circ_util = circ_upperRight;
break;
case U8G_CIRC_UPPER_LEFT:
u8g_DrawPixel(u8g, x0, y0 - rad);
u8g_DrawPixel(u8g, x0 - rad, y0);
circ_util = circ_upperLeft;
break;
case U8G_CIRC_LOWER_RIGHT:
u8g_DrawPixel(u8g, x0, y0 + rad);
u8g_DrawPixel(u8g, x0 + rad, y0);
circ_util = circ_lowerRight;
break;
case U8G_CIRC_LOWER_LEFT:
u8g_DrawPixel(u8g, x0, y0 + rad);
u8g_DrawPixel(u8g, x0 - rad, y0);
circ_util = circ_lowerLeft;
break;
default:
case U8G_CIRC_ALL:
u8g_DrawPixel(u8g, x0, y0 + rad);
u8g_DrawPixel(u8g, x0, y0 - rad);
u8g_DrawPixel(u8g, x0 + rad, y0);
u8g_DrawPixel(u8g, x0 - rad, y0);
circ_util = circ_all;
break;
}
while( x < y )
{
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
circ_util(u8g, x, y, x0, y0);
}
}
void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
{
if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
return;
int f = 1 - rad;
int ddF_x = 1;
int ddF_y = -2*rad;
uint8_t x = 0;
uint8_t y = rad;
// Draw vertical diameter at the horiz. center
// u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
if (option == U8G_CIRC_UPPER_LEFT || option == U8G_CIRC_UPPER_RIGHT) {
u8g_DrawVLine(u8g, x0, y0 - rad, rad+1);
}
else if (option == U8G_CIRC_LOWER_LEFT || option == U8G_CIRC_LOWER_RIGHT) {
u8g_DrawVLine(u8g, x0, y0, rad+1);
}
else {
u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
}
while( x < y )
{
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
//Draw vertical lines from one point to another
switch (option)
{
case U8G_CIRC_UPPER_RIGHT:
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
break;
case U8G_CIRC_UPPER_LEFT:
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
break;
case U8G_CIRC_LOWER_RIGHT:
u8g_DrawVLine(u8g, x0+x, y0, y+1);
u8g_DrawVLine(u8g, x0+y, y0, x+1);
break;
case U8G_CIRC_LOWER_LEFT:
u8g_DrawVLine(u8g, x0-x, y0, y+1);
u8g_DrawVLine(u8g, x0-y, y0, x+1);
break;
case U8G_CIRC_ALL:
u8g_DrawVLine(u8g, x0+x, y0-y, 2*y+1);
u8g_DrawVLine(u8g, x0-x, y0-y, 2*y+1);
u8g_DrawVLine(u8g, x0+y, y0-x, 2*x+1);
u8g_DrawVLine(u8g, x0-y, y0-x, 2*x+1);
break;
}
}
}
#endif
/*=========================================================================*/
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
{
/* upper right */
if ( option & U8G_DRAW_UPPER_RIGHT )
{
u8g_DrawPixel(u8g, x0 + x, y0 - y);
u8g_DrawPixel(u8g, x0 + y, y0 - x);
}
/* upper left */
if ( option & U8G_DRAW_UPPER_LEFT )
{
u8g_DrawPixel(u8g, x0 - x, y0 - y);
u8g_DrawPixel(u8g, x0 - y, y0 - x);
}
/* lower right */
if ( option & U8G_DRAW_LOWER_RIGHT )
{
u8g_DrawPixel(u8g, x0 + x, y0 + y);
u8g_DrawPixel(u8g, x0 + y, y0 + x);
}
/* lower left */
if ( option & U8G_DRAW_LOWER_LEFT )
{
u8g_DrawPixel(u8g, x0 - x, y0 + y);
u8g_DrawPixel(u8g, x0 - y, y0 + x);
}
}
void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
{
u8g_int_t f;
u8g_int_t ddF_x;
u8g_int_t ddF_y;
u8g_uint_t x;
u8g_uint_t y;
f = 1;
f -= rad;
ddF_x = 1;
ddF_y = 0;
ddF_y -= rad;
ddF_y *= 2;
x = 0;
y = rad;
u8g_draw_circle_section(u8g, x, y, x0, y0, option);
while ( x < y )
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
u8g_draw_circle_section(u8g, x, y, x0, y0, option);
}
}
void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
{
/* check for bounding box */
{
u8g_uint_t radp, radp2;
radp = rad;
radp++;
radp2 = radp;
radp2 *= 2;
if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
return;
}
/* draw circle */
u8g_draw_circle(u8g, x0, y0, rad, option);
}
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
{
/* upper right */
if ( option & U8G_DRAW_UPPER_RIGHT )
{
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
}
/* upper left */
if ( option & U8G_DRAW_UPPER_LEFT )
{
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
}
/* lower right */
if ( option & U8G_DRAW_LOWER_RIGHT )
{
u8g_DrawVLine(u8g, x0+x, y0, y+1);
u8g_DrawVLine(u8g, x0+y, y0, x+1);
}
/* lower left */
if ( option & U8G_DRAW_LOWER_LEFT )
{
u8g_DrawVLine(u8g, x0-x, y0, y+1);
u8g_DrawVLine(u8g, x0-y, y0, x+1);
}
}
void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
{
u8g_int_t f;
u8g_int_t ddF_x;
u8g_int_t ddF_y;
u8g_uint_t x;
u8g_uint_t y;
f = 1;
f -= rad;
ddF_x = 1;
ddF_y = 0;
ddF_y -= rad;
ddF_y *= 2;
x = 0;
y = rad;
u8g_draw_disc_section(u8g, x, y, x0, y0, option);
while ( x < y )
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
u8g_draw_disc_section(u8g, x, y, x0, y0, option);
}
}
void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
{
/* check for bounding box */
{
u8g_uint_t radp, radp2;
radp = rad;
radp++;
radp2 = radp;
radp2 *= 2;
if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
return;
}
/* draw disc */
u8g_draw_disc(u8g, x0, y0, rad, option);
}

@ -0,0 +1,156 @@
/*
u8g_clip.c
procedures for clipping
taken over from procs in u8g_pb.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Notes
This is one of the most critical parts of u8glib. It must be fast, but still reliable.
Based on the intersection program (see tools folder), there is minimized version of
the condition for the intersaction test:
minimized version
---1----0 1 b1 <= a2 && b1 > b2
-----1--0 1 b2 >= a1 && b1 > b2
---1-1--- 1 b1 <= a2 && b2 >= a1
It includes the assumption, that a1 <= a2 is always true (correct, because
a1, a2 are the page dimensions.
The direct implementation of the above result is done in:
uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
However, this is slower than a decision tree version:
static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
Also suprising is, that the macro implementation is slower than the inlined version.
The decision tree is based on the expansion of the truth table.
*/
#include "u8g.h"
#ifdef __GNUC__
#define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline))
#else
#define U8G_ALWAYS_INLINE
#endif
/*
intersection assumptions:
a1 <= a2 is always true
minimized version
---1----0 1 b1 <= a2 && b1 > b2
-----1--0 1 b2 >= a1 && b1 > b2
---1-1--- 1 b1 <= a2 && b2 >= a1
*/
#ifdef OLD_CODE_WHICH_IS_TOO_SLOW
static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
{
uint8_t c1, c2, c3, tmp;
c1 = v0 <= a1;
c2 = v1 >= a0;
c3 = v0 > v1;
tmp = c1;
c1 &= c2;
c2 &= c3;
c3 &= tmp;
c1 |= c2;
c1 |= c3;
return c1 & 1;
}
#endif
#define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) ))
//static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE;
static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
{
/* surprisingly the macro leads to larger code */
/* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */
if ( v0 <= a1 )
{
if ( v1 >= a0 )
{
return 1;
}
else
{
if ( v0 > v1 )
{
return 1;
}
else
{
return 0;
}
}
}
else
{
if ( v1 >= a0 )
{
if ( v0 > v1 )
{
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
}
uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
{
register u8g_uint_t tmp;
tmp = y;
tmp += h;
tmp--;
if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 )
return 0;
tmp = x;
tmp += w;
tmp--;
return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp);
}

@ -0,0 +1,173 @@
/*
u8g_com_api.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time)
{
return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL);
}
void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev)
{
dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL);
}
/* cs contains the chip number, which should be enabled */
void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs)
{
dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL);
}
void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev)
{
dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL);
}
void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev)
{
dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL);
}
void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address)
{
dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL);
}
uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val)
{
return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL);
}
uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq)
{
return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq);
}
uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq)
{
return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq);
}
/*
sequence := { direct_value | escape_sequence }
direct_value := 0..254
escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used
value_255 := 255 255
sequence_end = 255 254
delay := 255 0..127
adr := 255 0x0e0 .. 0x0ef
cs := 255 0x0d0 .. 0x0df
not_used := 255 101..254
#define U8G_ESC_DLY(x) 255, ((x) & 0x7f)
#define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f))
#define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f))
#define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01))
#define U8G_ESC_END 255, 254
#define U8G_ESC_255 255, 255
#define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f))
*/
uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq)
{
uint8_t is_escape = 0;
uint8_t value;
for(;;)
{
value = u8g_pgm_read(esc_seq);
if ( is_escape == 0 )
{
if ( value != 255 )
{
if ( u8g_WriteByte(u8g, dev, value) == 0 )
return 0;
}
else
{
is_escape = 1;
}
}
else
{
if ( value == 255 )
{
if ( u8g_WriteByte(u8g, dev, value) == 0 )
return 0;
}
else if ( value == 254 )
{
break;
}
else if ( value >= 0x0f0 )
{
/* not yet used, do nothing */
}
else if ( value >= 0xe0 )
{
u8g_SetAddress(u8g, dev, value & 0x0f);
}
else if ( value >= 0xd0 )
{
u8g_SetChipSelect(u8g, dev, value & 0x0f);
}
else if ( value >= 0xc0 )
{
u8g_SetResetLow(u8g, dev);
value &= 0x0f;
value <<= 4;
value+=2;
u8g_Delay(value);
u8g_SetResetHigh(u8g, dev);
u8g_Delay(value);
}
else if ( value >= 0xbe )
{
/* not yet implemented */
/* u8g_SetVCC(u8g, dev, value & 0x01); */
}
else if ( value <= 127 )
{
u8g_Delay(value);
}
is_escape = 0;
}
esc_seq++;
}
return 1;
}

@ -0,0 +1,94 @@
/*
u8g_com_api_16gr.c
Extension of the com api for devices with 16 graylevels (4 bit per pixel).
This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2),
mainly intended for SSD OLEDs
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
/* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */
/* topbit (msb) is sent last */
/* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */
uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
{
static uint8_t buf[4];
static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
buf [3] = map[b & 3];
b>>=2;
buf [2] = map[b & 3];
b>>=2;
buf [1] = map[b & 3];
b>>=2;
buf [0] = map[b & 3];
return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf);
}
uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
{
do
{
if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 )
return 0;
cnt--;
} while( cnt != 0 );
return 1;
}
/* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */
uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
{
//static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc};
//static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff};
static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff};
uint8_t bb;
bb = b;
bb &= 15;
b>>=4;
dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL);
return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL);
}
uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
{
do
{
if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 )
return 0;
cnt--;
} while( cnt != 0 );
return 1;
}

@ -0,0 +1,160 @@
/*
u8g_arduino_ATtiny85_std_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Uses code from tinySPI Written by Nick Gammon
// March 2013
// ATMEL ATTINY45 / ARDUINO pin mappings
//
// +-\/-+
// RESET Ain0 (D 5) PB5 1| |8 Vcc
// CLK1 Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 SCK / USCK / SCL
// CLK0 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 MISO / DO
// GND 4| |5 PB0 (D 0) pwm0 MOSI / DI / SDA
// +----+
#include "u8g.h"
#if defined(ARDUINO) && defined(__AVR_ATtiny85__)
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
const byte DI = 0; // D0, pin 5 Data In
const byte DO = 1; // D1, pin 6 Data Out (this is *not* MOSI)
const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock
uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val)
{
USIDR = val; // byte to output
USISR = _BV (USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero
do
{
USICR = _BV (USIWM0) // 3-wire mode
| _BV (USICS1) | _BV (USICLK) // Software clock strobe
| _BV (USITC); // Toggle Clock Port Pin
}
while ((USISR & _BV (USIOIF)) == 0); // until Counter Overflow Interrupt Flag set
return USIDR; // return read data
}
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed
pinMode (USCK, OUTPUT);
pinMode (DO, OUTPUT);
pinMode (u8g->pin_list[U8G_PI_CS], OUTPUT);
pinMode (u8g->pin_list[U8G_PI_A0], OUTPUT);
USICR = _BV (USIWM0); // 3-wire mode
u8g_MicroDelay();
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_MicroDelay();
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
u8g_MicroDelay();
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
u8g_MicroDelay();
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_arduino_ATtiny85_spi_out(arg_val);
u8g_MicroDelay();
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_arduino_ATtiny85_spi_out(*ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
u8g_MicroDelay();
break;
}
return 1;
}
#else /* ARDUINO */
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,75 @@
/*
u8g_com_arduino_common.c
shared procedures for the arduino communication procedures
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value)
{
uint8_t pin;
pin = u8g->pin_list[pin_index];
if ( pin != U8G_PIN_NONE )
digitalWrite(pin, value);
}
/* this procedure does not set the RW pin */
void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g)
{
uint8_t i;
/* skip the RW pin, which is the last pin in the list */
for( i = 0; i < U8G_PIN_LIST_LEN-1; i++ )
{
if ( u8g->pin_list[i] != U8G_PIN_NONE )
{
pinMode(u8g->pin_list[i], OUTPUT);
digitalWrite(u8g->pin_list[i], HIGH);
}
}
}
#endif

@ -0,0 +1,254 @@
/*
u8g_arduino_fast_parallel.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PIN_D0 8
PIN_D1 9
PIN_D2 10
PIN_D3 11
PIN_D4 4
PIN_D5 5
PIN_D6 6
PIN_D7 7
PIN_CS1 14
PIN_CS2 15
PIN_RW 16
PIN_DI 17
PIN_EN 18
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
//#include <WProgram.h>
#include <wiring_private.h>
#include <pins_arduino.h>
#else
#include <Arduino.h>
#endif
#define PIN_D0 8
#define PIN_D1 9
#define PIN_D2 10
#define PIN_D3 11
#define PIN_D4 4
#define PIN_D5 5
#define PIN_D6 6
#define PIN_D7 7
#define PIN_CS1 14
#define PIN_CS2 15
#define PIN_RW 16
#define PIN_DI 17
#define PIN_EN 18
//#define PIN_RESET
#if defined(__PIC32MX)
/* CHIPKIT PIC32 */
static volatile uint32_t *u8g_data_port[8];
static uint32_t u8g_data_mask[8];
#else
static volatile uint8_t *u8g_data_port[8];
static uint8_t u8g_data_mask[8];
#endif
static void u8g_com_arduino_fast_parallel_init(u8g_t *u8g)
{
u8g_data_port[0] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0]));
u8g_data_mask[0] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D0]);
u8g_data_port[1] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1]));
u8g_data_mask[1] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D1]);
u8g_data_port[2] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2]));
u8g_data_mask[2] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D2]);
u8g_data_port[3] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3]));
u8g_data_mask[3] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D3]);
u8g_data_port[4] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4]));
u8g_data_mask[4] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D4]);
u8g_data_port[5] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5]));
u8g_data_mask[5] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D5]);
u8g_data_port[6] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6]));
u8g_data_mask[6] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D6]);
u8g_data_port[7] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7]));
u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]);
}
/* atomic protection must be done by calling function */
static void u8g_com_arduino_fast_write_data_pin(uint8_t pin, uint8_t val)
{
if ( val != 0 )
*u8g_data_port[pin] |= u8g_data_mask[pin];
else
*u8g_data_port[pin] &= ~u8g_data_mask[pin];
}
void u8g_com_arduino_fast_parallel_write(u8g_t *u8g, uint8_t val)
{
U8G_ATOMIC_START();
u8g_com_arduino_fast_write_data_pin( 0, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 1, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 2, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 3, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 4, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 5, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 6, val&1 );
val >>= 1;
u8g_com_arduino_fast_write_data_pin( 7, val&1 );
val >>= 1;
U8G_ATOMIC_END();
/* EN cycle time must be 1 micro second */
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH);
u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW);
u8g_10MicroDelay(); /* ST7920 commands: 72us */
u8g_10MicroDelay(); /* ST7920 commands: 72us */
}
uint8_t u8g_com_arduino_fast_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_fast_parallel_init(u8g);
/* setup the RW pin as output and force it to low */
if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE )
{
pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT);
u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW);
}
/* set all pins (except RW pin) */
u8g_com_arduino_assign_pin_output_high(u8g);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
}
else if ( arg_val == 1 )
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
}
else if ( arg_val == 2 )
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_fast_parallel_write(u8g, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_fast_parallel_write(u8g, *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_fast_parallel_write(u8g, u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val);
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_arduino_fast_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,438 @@
/*
u8g_com_arduino_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SPI Clock Cycle Type
SSD1351 50ns 20 MHz
SSD1322 300ns 3.3 MHz
SSD1327 300ns
SSD1306 300ns
ST7565 400ns 2.5 MHz
ST7920 400ns
Arduino DUE
PA25 MISO
PA26 MOSI 75
PA27 SCLK 76
typedef struct {
WoReg SPI_CR; (Spi Offset: 0x00) Control Register
RwReg SPI_MR; (Spi Offset: 0x04) Mode Register
RoReg SPI_RDR; (Spi Offset: 0x08) Receive Data Register
WoReg SPI_TDR; (Spi Offset: 0x0C) Transmit Data Register
RoReg SPI_SR; (Spi Offset: 0x10) Status Register
WoReg SPI_IER; (Spi Offset: 0x14) Interrupt Enable Register
WoReg SPI_IDR; (Spi Offset: 0x18) Interrupt Disable Register
RoReg SPI_IMR; (Spi Offset: 0x1C) Interrupt Mask Register
RoReg Reserved1[4];
RwReg SPI_CSR[4]; (Spi Offset: 0x30) Chip Select Register
RoReg Reserved2[41];
RwReg SPI_WPMR; (Spi Offset: 0xE4) Write Protection Control Register
RoReg SPI_WPSR; (Spi Offset: 0xE8) Write Protection Status Register
} Spi;
Power Management Controller (PMC)
arduino-1.5.2/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/instance/instance_pmc.h
- enable PIO
REG_PMC_PCER0 = 1UL << ID_PIOA
- enable SPI
REG_PMC_PCER0 = 1UL << ID_SPI0
- enable PIOA and SPI0
REG_PMC_PCER0 = (1UL << ID_PIOA) | (1UL << ID_SPI0);
Parallel Input/Output Controller (PIO)
arduino-1.5.2/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/instance/instance_pioa.h
- enable special function of the pin: disable PIO on A26 and A27:
REG_PIOA_PDR = 0x0c000000
PIOA->PIO_PDR = 0x0c000000
SPI
SPI0->SPI_CR = SPI_CR_SPIDIS
SPI0->SPI_CR = SPI_CR_SWRST ;
SPI0->SPI_CR = SPI_CR_SWRST ;
SPI0->SPI_CR = SPI_CR_SPIEN
Bit 0: Master Mode = 1 (active)
Bit 1: Peripheral Select = 0 (fixed)
Bit 2: Chip Select Decode Mode = 1 (4 to 16)
Bit 4: Mode Fault Detection = 1 (disabled)
Bit 5: Wait Data Read = 0 (disabled)
Bit 7: Loop Back Mode = 0 (disabled)
Bit 16-19: Peripheral Chip Select = 0 (chip select 0)
SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PCSDEC | SPI_MR_MODFDIS
Bit 0: Clock Polarity = 0
Bit 1: Clock Phase = 0
Bit 4-7: Bits = 0 (8 Bit)
Bit 8-15: SCBR = 1
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(x) Serial Baud Rate
SCBR / 84000000 > 50 / 1000000000
SCBR / 84 > 5 / 100
SCBR > 50 *84 / 1000 --> SCBR=5
SCBR > 300*84 / 1000 --> SCBR=26
SCBR > 400*84 / 1000 --> SCBR=34
Arduino Due test code:
REG_PMC_PCER0 = (1UL << ID_PIOA) | (1UL << ID_SPI0);
REG_PIOA_PDR = 0x0c000000;
SPI0->SPI_CR = SPI_CR_SPIDIS;
SPI0->SPI_CR = SPI_CR_SWRST;
SPI0->SPI_CR = SPI_CR_SWRST;
SPI0->SPI_CR = SPI_CR_SPIEN;
SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PCSDEC | SPI_MR_MODFDIS;
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(30);
for(;;)
{
while( (SPI0->SPI_SR & SPI_SR_TDRE) == 0 )
;
SPI0->SPI_TDR = 0x050;
}
*/
#include "u8g.h"
#if defined(ARDUINO)
#if defined(__AVR__)
#define U8G_ARDUINO_ATMEGA_HW_SPI
/* remove the definition for attiny */
#if __AVR_ARCH__ == 2
#undef U8G_ARDUINO_ATMEGA_HW_SPI
#endif
#if __AVR_ARCH__ == 25
#undef U8G_ARDUINO_ATMEGA_HW_SPI
#endif
#endif
#if defined(U8G_ARDUINO_ATMEGA_HW_SPI)
#include <avr/interrupt.h>
#include <avr/io.h>
#if ARDUINO < 100
#include <WProgram.h>
/* fixed pins */
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) // Sanguino.cc board
#define PIN_SCK 7
#define PIN_MISO 6
#define PIN_MOSI 5
#define PIN_CS 4
#else // Arduino Board
#define PIN_SCK 13
#define PIN_MISO 12
#define PIN_MOSI 11
#define PIN_CS 10
#endif // (__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
#else
#include <Arduino.h>
/* use Arduino pin definitions */
#define PIN_SCK SCK
#define PIN_MISO MISO
#define PIN_MOSI MOSI
#define PIN_CS SS
#endif
//static uint8_t u8g_spi_out(uint8_t data) U8G_NOINLINE;
static uint8_t u8g_spi_out(uint8_t data)
{
/* unsigned char x = 100; */
/* send data */
SPDR = data;
/* wait for transmission */
while (!(SPSR & (1<<SPIF)))
;
/* clear the SPIF flag by reading SPDR */
return SPDR;
}
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
pinMode(PIN_SCK, OUTPUT);
digitalWrite(PIN_SCK, LOW);
pinMode(PIN_MOSI, OUTPUT);
digitalWrite(PIN_MOSI, LOW);
/* pinMode(PIN_MISO, INPUT); */
pinMode(PIN_CS, OUTPUT); /* system chip select for the atmega board */
digitalWrite(PIN_CS, HIGH);
/*
SPR1 SPR0
0 0 fclk/4
0 1 fclk/16
1 0 fclk/64
1 1 fclk/128
*/
SPCR = 0;
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(0<<CPOL)|(0<<CPHA);
#ifdef U8G_HW_SPI_2X
SPSR = (1 << SPI2X); /* double speed, issue 89 */
#else
if ( arg_val <= U8G_SPI_CLK_CYCLE_50NS )
{
SPSR = (1 << SPI2X); /* double speed, issue 89 */
}
#endif
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_spi_out(arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_spi_out(*ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_spi_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
/* #elif defined(__18CXX) || defined(__PIC32MX) */
#elif defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__
#include <Arduino.h>
/* use Arduino pin definitions */
#define PIN_SCK SCK
#define PIN_MISO MISO
#define PIN_MOSI MOSI
#define PIN_CS SS
static uint8_t u8g_spi_out(uint8_t data)
{
/* wait until tx register is empty */
while( (SPI0->SPI_SR & SPI_SR_TDRE) == 0 )
;
/* send data */
SPI0->SPI_TDR = (uint32_t)data;
return data;
}
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
/* Arduino Due specific code */
/* enable PIOA and SPI0 */
REG_PMC_PCER0 = (1UL << ID_PIOA) | (1UL << ID_SPI0);
/* disable PIO on A26 and A27 */
REG_PIOA_PDR = 0x0c000000;
/* reset SPI0 (from sam lib) */
SPI0->SPI_CR = SPI_CR_SPIDIS;
SPI0->SPI_CR = SPI_CR_SWRST;
SPI0->SPI_CR = SPI_CR_SWRST;
SPI0->SPI_CR = SPI_CR_SPIEN;
u8g_MicroDelay();
/* master mode, no fault detection, chip select 0 */
SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PCSDEC | SPI_MR_MODFDIS;
/* Polarity, Phase, 8 Bit data transfer, baud rate */
/* x * 1000 / 84 --> clock cycle in ns
5 * 1000 / 84 = 58 ns
SCBR > 50 *84 / 1000 --> SCBR=5
SCBR > 300*84 / 1000 --> SCBR=26
SCBR > 400*84 / 1000 --> SCBR=34
*/
if ( arg_val <= U8G_SPI_CLK_CYCLE_50NS )
{
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(5) | 1;
}
else if ( arg_val <= U8G_SPI_CLK_CYCLE_300NS )
{
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(26) | 1;
}
else if ( arg_val <= U8G_SPI_CLK_CYCLE_400NS )
{
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(34) | 1;
}
else
{
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(84) | 1;
}
u8g_MicroDelay();
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
u8g_MicroDelay();
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_MicroDelay(); /* this delay is required to avoid that the display is switched off too early --> DOGS102 with DUE */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
u8g_MicroDelay();
}
else
{
/* enable */
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
u8g_MicroDelay();
}
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_spi_out(arg_val);
u8g_MicroDelay();
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_spi_out(*ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_spi_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
#else /* U8G_ARDUINO_ATMEGA_HW_SPI */
#endif /* U8G_ARDUINO_ATMEGA_HW_SPI */
#else /* ARDUINO */
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,159 @@
/*
u8g_com_arduino_hw_usart_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SPI Clock Cycle Type
SSD1351 50ns 20 MHz
SSD1322 300ns 3.3 MHz
SSD1327 300ns
SSD1306 300ns
ST7565 400ns 2.5 MHz
ST7920 400ns
*/
#include "u8g.h"
#if defined(ARDUINO)
#if defined(__AVR_ATmega32U4__ )
#include <avr/interrupt.h>
#include <avr/io.h>
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
static uint8_t u8g_usart_spi_out(uint8_t data)
{
/* send data */
UDR1 = data;
/* wait for empty transmit buffer */
while(!(UCSR1A & (1 << UDRE1)));
return UDR1;
}
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
/* SCK is already an output as we overwrite TXLED */
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
// Init interface at 2MHz
UBRR1 = 0x00;
UCSR1C = (1 << UMSEL11) | (1 << UMSEL10);
UCSR1B = (1 << TXEN1);
UBRR1 = 3;
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_usart_spi_out(arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_usart_spi_out(*ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_usart_spi_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
/* #elif defined(__18CXX) || defined(__PIC32MX) */
/* #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ */
#else /* __AVR_ATmega32U4__ */
#endif /* __AVR_ATmega32U4__ */
#else /* ARDUINO */
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,234 @@
/*
u8g_arduino_no_en_parallel.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PIN_D0 8
PIN_D1 9
PIN_D2 10
PIN_D3 11
PIN_D4 4
PIN_D5 5
PIN_D6 6
PIN_D7 7
PIN_CS1 14
PIN_CS2 15
PIN_RW 16
PIN_DI 17
PIN_EN 18
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
//#include <WProgram.h>
#include <wiring_private.h>
#include <pins_arduino.h>
#else
#include <Arduino.h>
#endif
//#define PIN_RESET
#if defined(__PIC32MX)
/* CHIPKIT PIC32 */
static volatile uint32_t *u8g_data_port[8];
static uint32_t u8g_data_mask[8];
#else
static volatile uint8_t *u8g_data_port[8];
static uint8_t u8g_data_mask[8];
#endif
static void u8g_com_arduino_no_en_parallel_init(u8g_t *u8g)
{
u8g_data_port[0] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0]));
u8g_data_mask[0] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D0]);
u8g_data_port[1] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1]));
u8g_data_mask[1] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D1]);
u8g_data_port[2] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2]));
u8g_data_mask[2] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D2]);
u8g_data_port[3] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3]));
u8g_data_mask[3] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D3]);
u8g_data_port[4] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4]));
u8g_data_mask[4] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D4]);
u8g_data_port[5] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5]));
u8g_data_mask[5] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D5]);
u8g_data_port[6] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6]));
u8g_data_mask[6] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D6]);
u8g_data_port[7] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7]));
u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]);
}
/* No atomic protcetion. This is done by caller */
static void u8g_com_arduino_no_en_write_data_pin(uint8_t pin, uint8_t val)
{
if ( val != 0 )
{
*u8g_data_port[pin] |= u8g_data_mask[pin];
}
else
{
*u8g_data_port[pin] &= ~u8g_data_mask[pin];
}
}
void u8g_com_arduino_no_en_parallel_write(u8g_t *u8g, uint8_t val)
{
U8G_ATOMIC_START();
u8g_com_arduino_no_en_write_data_pin( 0, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 1, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 2, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 3, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 4, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 5, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 6, val&1 );
val >>= 1;
u8g_com_arduino_no_en_write_data_pin( 7, val&1 );
val >>= 1;
U8G_ATOMIC_END();
/* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */
if ( u8g->pin_list[U8G_PI_CS_STATE] == 1 )
{
u8g_MicroDelay();
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_MicroDelay();
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_MicroDelay();
}
else if ( u8g->pin_list[U8G_PI_CS_STATE] == 2 )
{
u8g_MicroDelay();
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
u8g_MicroDelay();
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
u8g_MicroDelay();
}
}
uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_no_en_parallel_init(u8g);
/* setup the RW pin as output and force it to low */
if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE )
{
pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT);
u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW);
}
/* set all pins (except RW pin) */
u8g_com_arduino_assign_pin_output_high(u8g);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
/*
0: nothing selected
1: CS1 will be used as enable line
2: CS2 will be used as enable line
this will be used in the u8g_com_arduino_no_en_parallel_write() procedure
*/
u8g->pin_list[U8G_PI_CS_STATE] = arg_val;
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_no_en_parallel_write(u8g, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_no_en_parallel_write(u8g, *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_no_en_parallel_write(u8g, u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val);
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,184 @@
/*
u8g_com_arduino_parallel.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PIN_D0 8
PIN_D1 9
PIN_D2 10
PIN_D3 11
PIN_D4 4
PIN_D5 5
PIN_D6 6
PIN_D7 7
PIN_CS1 14
PIN_CS2 15
PIN_RW 16
PIN_DI 17
PIN_EN 18
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
void u8g_com_arduino_parallel_write(u8g_t *u8g, uint8_t val)
{
u8g_com_arduino_digital_write(u8g, U8G_PI_D0, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D1, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D2, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D3, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D4, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D5, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D6, val&1);
val >>= 1;
u8g_com_arduino_digital_write(u8g, U8G_PI_D7, val&1);
/* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH);
u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW);
u8g_10MicroDelay(); /* ST7920 commands: 72us */
}
uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
/* setup the RW pin as output and force it to low */
if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE )
{
pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT);
u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW);
}
/* set all pins (except RW pin) */
u8g_com_arduino_assign_pin_output_high(u8g);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
}
else if ( arg_val == 1 )
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
}
else if ( arg_val == 2 )
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_parallel_write(u8g, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_parallel_write(u8g, *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_parallel_write(u8g, u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val);
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,177 @@
/*
u8g_arduino_port_d_wr.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Assumes PORTD for 8 bit data transfer.
EN is assumed to be a low active write signal (WR)
ILI9325D_320x240 from iteadstudio.com
RS=19, WR=18, CS=17, RST=16
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO) && defined(PORTD)
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
static void u8g_com_arduino_port_d_8bit_wr(u8g_t *u8g, uint8_t val)
{
PORTD = val;
/* WR cycle time must be 1 micro second, digitalWrite is slow enough to do this */
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH);
}
uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
#ifdef UCSR0B
UCSR0B = 0; // disable USART 0
#endif
U8G_ATOMIC_START();
DDRD = 0x0ff;
PORTD = 0x0ff;
U8G_ATOMIC_END();
/* setup the RW pin as output and force it to low */
if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE )
{
pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT);
u8g_com_arduino_digital_write(u8g, U8G_PI_RW, HIGH);
}
/* set all pins (except RW pin) */
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
}
else if ( arg_val == 1 )
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH);
}
else if ( arg_val == 2 )
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_port_d_8bit_wr(u8g, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_port_d_8bit_wr(u8g, *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_port_d_8bit_wr(u8g, u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val);
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO && PORTD */

@ -0,0 +1,212 @@
/*
u8g_com_arduino_ssd_i2c.c
com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant
I2C protocol
ToDo: Rename this to u8g_com_avr_ssd_i2c.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Special pin usage:
U8G_PI_I2C_OPTION additional options
U8G_PI_A0_STATE used to store the last value of the command/data register selection
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
U8G_PI_SCL clock line (NOT USED)
U8G_PI_SDA data line (NOT USED)
U8G_PI_RESET reset line (currently disabled, see below)
Protocol:
SLA, Cmd/Data Selection, Arguments
The command/data register is selected by a special instruction byte, which is sent after SLA
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
*/
#include "u8g.h"
#if defined(U8G_WITH_PINLIST)
#define I2C_SLA (0x3c*2)
//#define I2C_CMD_MODE 0x080
#define I2C_CMD_MODE 0x000
#define I2C_DATA_MODE 0x040
uint8_t u8g_com_arduino_ssd_start_sequence(u8g_t *u8g)
{
/* are we requested to set the a0 state? */
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
return 1;
/* setup bus, might be a repeated start */
if ( u8g_i2c_start(I2C_SLA) == 0 )
return 0;
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
{
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
return 0;
}
else
{
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
return 0;
}
u8g->pin_list[U8G_PI_SET_A0] = 0;
return 1;
}
uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
//u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
//u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
/* Currently disabled, but it could be enable. Previous restrictions have been removed */
/* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */
break;
case U8G_COM_MSG_CHIP_SELECT:
u8g->pin_list[U8G_PI_A0_STATE] = 0;
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
if ( arg_val == 0 )
{
/* disable chip, send stop condition */
u8g_i2c_stop();
}
else
{
/* enable, do nothing: any byte writing will trigger the i2c start */
}
break;
case U8G_COM_MSG_WRITE_BYTE:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
if ( u8g_i2c_send_byte(arg_val) == 0 )
return u8g_i2c_stop(), 0;
// u8g_i2c_stop();
break;
case U8G_COM_MSG_WRITE_SEQ:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
if ( u8g_i2c_send_byte(*ptr++) == 0 )
return u8g_i2c_stop(), 0;
arg_val--;
}
}
// u8g_i2c_stop();
break;
case U8G_COM_MSG_WRITE_SEQ_P:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
return 0;
ptr++;
arg_val--;
}
}
// u8g_i2c_stop();
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
#ifdef OLD_CODE
if ( i2c_state != 0 )
{
u8g_i2c_stop();
i2c_state = 0;
}
if ( u8g_com_arduino_ssd_start_sequence(arg_val) == 0 )
return 0;
/* setup bus, might be a repeated start */
/*
if ( u8g_i2c_start(I2C_SLA) == 0 )
return 0;
if ( arg_val == 0 )
{
i2c_state = 1;
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
return 0;
}
else
{
i2c_state = 2;
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
return 0;
}
*/
#endif
break;
}
return 1;
}
#else /* defined(U8G_WITH_PINLIST) */
uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* defined(U8G_WITH_PINLIST) */

@ -0,0 +1,330 @@
/*
u8g_com_arduino_st7920_custom.c
Additional COM device, initially introduced for 3D Printer community
Implements a fast SW SPI com subsystem
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
A special SPI interface for ST7920 controller
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#include "wiring_private.h"
#include "pins_arduino.h"
#else
#include <Arduino.h>
#include "wiring_private.h"
#endif
#if defined(__AVR__)
static uint8_t u8g_bitData, u8g_bitNotData;
static uint8_t u8g_bitClock, u8g_bitNotClock;
static volatile uint8_t *u8g_outData;
static volatile uint8_t *u8g_outClock;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
u8g_outClock = portOutputRegister(digitalPinToPort(clockPin));
u8g_bitData = digitalPinToBitMask(dataPin);
u8g_bitClock = digitalPinToBitMask(clockPin);
u8g_bitNotClock = u8g_bitClock;
u8g_bitNotClock ^= 0x0ff;
u8g_bitNotData = u8g_bitData;
u8g_bitNotData ^= 0x0ff;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) U8G_NOINLINE;
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
uint8_t bitData = u8g_bitData;
uint8_t bitNotData = u8g_bitNotData;
uint8_t bitClock = u8g_bitClock;
uint8_t bitNotClock = u8g_bitNotClock;
volatile uint8_t *outData = u8g_outData;
volatile uint8_t *outClock = u8g_outClock;
U8G_ATOMIC_START();
bitData |= *outData;
bitNotData &= *outData;
do
{
if ( val & 128 )
*outData = bitData;
else
*outData = bitNotData;
/*
*outClock |= bitClock;
val <<= 1;
cnt--;
*outClock &= bitNotClock;
*/
val <<= 1;
*outClock &= bitNotClock;
cnt--;
// removed micro delays, because AVRs are too slow and the delay is not required
//u8g_MicroDelay();
*outClock |= bitClock;
//u8g_MicroDelay();
} while( cnt != 0 );
U8G_ATOMIC_END();
}
#elif defined(__18CXX) || defined(__PIC32MX)
uint16_t dog_bitData, dog_bitNotData;
uint16_t dog_bitClock, dog_bitNotClock;
volatile uint32_t *dog_outData;
volatile uint32_t *dog_outClock;
volatile uint32_t dog_pic32_spi_tmp;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
dog_outData = portOutputRegister(digitalPinToPort(dataPin));
dog_outClock = portOutputRegister(digitalPinToPort(clockPin));
dog_bitData = digitalPinToBitMask(dataPin);
dog_bitClock = digitalPinToBitMask(clockPin);
dog_bitNotClock = dog_bitClock;
dog_bitNotClock ^= 0x0ffff;
dog_bitNotData = dog_bitData;
dog_bitNotData ^= 0x0ffff;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
U8G_ATOMIC_START();
do
{
if ( val & 128 )
*dog_outData |= dog_bitData;
else
*dog_outData &= dog_bitNotData;
val <<= 1;
//u8g_MicroDelay();
//*dog_outClock |= dog_bitClock;
*dog_outClock &= dog_bitNotClock;
cnt--;
u8g_MicroDelay();
//*dog_outClock &= dog_bitNotClock;
*dog_outClock |= dog_bitClock;
u8g_MicroDelay();
} while( cnt != 0 );
U8G_ATOMIC_END();
}
#else
/* default interface, Arduino DUE (__arm__) */
uint8_t u8g_data_custom_pin;
uint8_t u8g_clock_custom_pin;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
u8g_data_custom_pin = dataPin;
u8g_clock_custom_pin = clockPin;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
do
{
if ( val & 128 )
digitalWrite(u8g_data_custom_pin, HIGH);
else
digitalWrite(u8g_data_custom_pin, LOW);
val <<= 1;
//u8g_MicroDelay();
digitalWrite(u8g_clock_custom_pin, LOW);
cnt--;
u8g_MicroDelay();
digitalWrite(u8g_clock_custom_pin, HIGH);
u8g_MicroDelay();
} while( cnt != 0 );
}
#endif
static void u8g_com_arduino_st7920_write_byte_seq(uint8_t rs, uint8_t *ptr, uint8_t len)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
}
while( len > 0 )
{
u8g_com_arduino_do_shift_out_msb_first(*ptr & 0x0f0);
u8g_com_arduino_do_shift_out_msb_first(*ptr << 4);
ptr++;
len--;
u8g_10MicroDelay();
}
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
}
u8g_com_arduino_do_shift_out_msb_first(val & 0x0f0);
u8g_com_arduino_do_shift_out_msb_first(val << 4);
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
// u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW);
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable, note: the st7920 has an active high chip select */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
else
{
/* enable */
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_st7920_write_byte( u8g->pin_list[U8G_PI_A0_STATE], arg_val);
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
u8g_com_arduino_st7920_write_byte_seq(u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_st7920_write_byte(u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr) );
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
break;
}
return 1;
}
#else /* ARDUINO */
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,293 @@
/*
u8g_com_arduino_st7920_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
A special HW SPI interface for ST7920 controller
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#include "wiring_private.h"
#include "pins_arduino.h"
#else
#include <Arduino.h>
#include "wiring_private.h"
#endif
#if defined(__AVR__)
#define U8G_ARDUINO_ATMEGA_HW_SPI
/* remove the definition for attiny */
#if __AVR_ARCH__ == 2
#undef U8G_ARDUINO_ATMEGA_HW_SPI
#endif
#if __AVR_ARCH__ == 25
#undef U8G_ARDUINO_ATMEGA_HW_SPI
#endif
#endif
#if defined(U8G_ARDUINO_ATMEGA_HW_SPI)
#include <avr/interrupt.h>
#include <avr/io.h>
#if ARDUINO < 100
/* fixed pins */
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) // Sanguino.cc board
#define PIN_SCK 7
#define PIN_MISO 6
#define PIN_MOSI 5
#define PIN_CS 4
#else // Arduino Board
#define PIN_SCK 13
#define PIN_MISO 12
#define PIN_MOSI 11
#define PIN_CS 10
#endif // (__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
#else
/* use Arduino pin definitions */
#define PIN_SCK SCK
#define PIN_MISO MISO
#define PIN_MOSI MOSI
#define PIN_CS SS
#endif
static uint8_t u8g_arduino_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE;
static uint8_t u8g_arduino_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val)
{
/* send data */
SPDR = val;
/* wait for transmission */
while (!(SPSR & (1<<SPIF)))
;
/* clear the SPIF flag by reading SPDR */
return SPDR;
}
static void u8g_com_arduino_st7920_write_byte_hw_spi_seq(u8g_t *u8g, uint8_t rs, uint8_t *ptr, uint8_t len)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_arduino_st7920_hw_spi_shift_out(u8g, 0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_arduino_st7920_hw_spi_shift_out(u8g, 0x0fa);
}
while( len > 0 )
{
u8g_arduino_st7920_hw_spi_shift_out(u8g, *ptr & 0x0f0);
u8g_arduino_st7920_hw_spi_shift_out(u8g, *ptr << 4);
ptr++;
len--;
u8g_10MicroDelay();
}
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
static void u8g_com_arduino_st7920_write_byte_hw_spi(u8g_t *u8g, uint8_t rs, uint8_t val) U8G_NOINLINE;
static void u8g_com_arduino_st7920_write_byte_hw_spi(u8g_t *u8g, uint8_t rs, uint8_t val)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_arduino_st7920_hw_spi_shift_out(u8g, 0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_arduino_st7920_hw_spi_shift_out(u8g, 0x0fa);
}
else
{
/* do nothing, keep same state */
}
u8g_arduino_st7920_hw_spi_shift_out(u8g, val & 0x0f0);
u8g_arduino_st7920_hw_spi_shift_out(u8g, val << 4);
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
/* code from u8g_com-arduino_hw_spi.c */
pinMode(PIN_SCK, OUTPUT);
digitalWrite(PIN_SCK, LOW);
pinMode(PIN_MOSI, OUTPUT);
digitalWrite(PIN_MOSI, LOW);
/* pinMode(PIN_MISO, INPUT); */
pinMode(PIN_CS, OUTPUT); /* system chip select for the atmega board */
digitalWrite(PIN_CS, HIGH);
//u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
#ifdef OBSOLETE
DDRB |= _BV(3); /* D0, MOSI */
DDRB |= _BV(5); /* SCK */
DDRB |= _BV(2); /* slave select */
PORTB &= ~_BV(3); /* D0, MOSI = 0 */
PORTB &= ~_BV(5); /* SCK = 0 */
#endif
/*
SPR1 SPR0
0 0 fclk/4
0 1 fclk/16
1 0 fclk/64
1 1 fclk/128
*/
SPCR = 0;
/* 20 Dez 2012: set CPOL and CPHA to 1 !!! */
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(1<<CPOL)|(1<<CPHA);
#ifdef U8G_HW_SPI_2X
SPSR = (1 << SPI2X); /* double speed, issue 89 */
#endif
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable, note: the st7920 has an active high chip select */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
else
{
/* enable */
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], arg_val);
// u8g->pin_list[U8G_PI_A0_STATE] = 2;
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
u8g_com_arduino_st7920_write_byte_hw_spi_seq(u8g, u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
/*
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
arg_val--;
}
}
*/
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr) );
// u8g->pin_list[U8G_PI_A0_STATE] = 2;
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
break;
}
return 1;
}
#else
uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif
#else /* ARDUINO */
uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,330 @@
/*
u8g_com_arduino_st7920_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
A special SPI interface for ST7920 controller
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#include "wiring_private.h"
#include "pins_arduino.h"
#else
#include <Arduino.h>
#include "wiring_private.h"
#endif
#if defined(__AVR__)
static uint8_t u8g_bitData, u8g_bitNotData;
static uint8_t u8g_bitClock, u8g_bitNotClock;
static volatile uint8_t *u8g_outData;
static volatile uint8_t *u8g_outClock;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
u8g_outClock = portOutputRegister(digitalPinToPort(clockPin));
u8g_bitData = digitalPinToBitMask(dataPin);
u8g_bitClock = digitalPinToBitMask(clockPin);
u8g_bitNotClock = u8g_bitClock;
u8g_bitNotClock ^= 0x0ff;
u8g_bitNotData = u8g_bitData;
u8g_bitNotData ^= 0x0ff;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) U8G_NOINLINE;
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
uint8_t bitData = u8g_bitData;
uint8_t bitNotData = u8g_bitNotData;
uint8_t bitClock = u8g_bitClock;
uint8_t bitNotClock = u8g_bitNotClock;
volatile uint8_t *outData = u8g_outData;
volatile uint8_t *outClock = u8g_outClock;
U8G_ATOMIC_START();
bitData |= *outData;
bitNotData &= *outData;
do
{
if ( val & 128 )
*outData = bitData;
else
*outData = bitNotData;
/*
*outClock |= bitClock;
val <<= 1;
cnt--;
*outClock &= bitNotClock;
*/
val <<= 1;
*outClock &= bitNotClock;
cnt--;
// removed micro delays, because AVRs are too slow and the delay is not required
//u8g_MicroDelay();
*outClock |= bitClock;
//u8g_MicroDelay();
} while( cnt != 0 );
U8G_ATOMIC_END();
}
#elif defined(__18CXX) || defined(__PIC32MX)
uint16_t dog_bitData, dog_bitNotData;
uint16_t dog_bitClock, dog_bitNotClock;
volatile uint32_t *dog_outData;
volatile uint32_t *dog_outClock;
volatile uint32_t dog_pic32_spi_tmp;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
dog_outData = portOutputRegister(digitalPinToPort(dataPin));
dog_outClock = portOutputRegister(digitalPinToPort(clockPin));
dog_bitData = digitalPinToBitMask(dataPin);
dog_bitClock = digitalPinToBitMask(clockPin);
dog_bitNotClock = dog_bitClock;
dog_bitNotClock ^= 0x0ffff;
dog_bitNotData = dog_bitData;
dog_bitNotData ^= 0x0ffff;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
U8G_ATOMIC_START();
do
{
if ( val & 128 )
*dog_outData |= dog_bitData;
else
*dog_outData &= dog_bitNotData;
val <<= 1;
//u8g_MicroDelay();
//*dog_outClock |= dog_bitClock;
*dog_outClock &= dog_bitNotClock;
cnt--;
u8g_MicroDelay();
//*dog_outClock &= dog_bitNotClock;
*dog_outClock |= dog_bitClock;
u8g_MicroDelay();
} while( cnt != 0 );
U8G_ATOMIC_END();
}
#else
/* default interface, Arduino DUE (__arm__) */
uint8_t u8g_data_pin;
uint8_t u8g_clock_pin;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
u8g_data_pin = dataPin;
u8g_clock_pin = clockPin;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
do
{
if ( val & 128 )
digitalWrite(u8g_data_pin, HIGH);
else
digitalWrite(u8g_data_pin, LOW);
val <<= 1;
//u8g_MicroDelay();
digitalWrite(u8g_clock_pin, LOW);
cnt--;
u8g_MicroDelay();
digitalWrite(u8g_clock_pin, HIGH);
u8g_MicroDelay();
} while( cnt != 0 );
}
#endif
static void u8g_com_arduino_st7920_write_byte_seq(uint8_t rs, uint8_t *ptr, uint8_t len)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
}
while( len > 0 )
{
u8g_com_arduino_do_shift_out_msb_first(*ptr & 0x0f0);
u8g_com_arduino_do_shift_out_msb_first(*ptr << 4);
ptr++;
len--;
u8g_10MicroDelay();
}
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
}
u8g_com_arduino_do_shift_out_msb_first(val & 0x0f0);
u8g_com_arduino_do_shift_out_msb_first(val << 4);
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
// u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW);
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable, note: the st7920 has an active high chip select */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
else
{
/* enable */
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
/* 28 Dec 2013 reassign pins, fixes issue with more than one display */
/* issue 227 */
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_st7920_write_byte( u8g->pin_list[U8G_PI_A0_STATE], arg_val);
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
u8g_com_arduino_st7920_write_byte_seq(u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_st7920_write_byte(u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr) );
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
break;
}
return 1;
}
#else /* ARDUINO */
uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,143 @@
/*
u8g_arduino_std_sw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
void u8g_arduino_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val)
{
uint8_t i = 8;
do
{
if ( val & 128 )
digitalWrite(dataPin, HIGH);
else
digitalWrite(dataPin, LOW);
val <<= 1;
u8g_MicroDelay(); /* 23 Sep 2012 */
//delay(1);
digitalWrite(clockPin, HIGH);
u8g_MicroDelay(); /* 23 Sep 2012 */
//delay(1);
digitalWrite(clockPin, LOW);
u8g_MicroDelay(); /* 23 Sep 2012 */
//delay(1);
i--;
} while( i != 0 );
}
uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
break;
}
return 1;
}
#else /* ARDUINO */
uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,301 @@
/*
u8g_arduino_sw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#include "wiring_private.h"
#include "pins_arduino.h"
#else
#include <Arduino.h>
#include "wiring_private.h"
#endif
/*=========================================================*/
/* Arduino, AVR */
#if defined(__AVR__)
uint8_t u8g_bitData, u8g_bitNotData;
uint8_t u8g_bitClock, u8g_bitNotClock;
volatile uint8_t *u8g_outData;
volatile uint8_t *u8g_outClock;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
u8g_outClock = portOutputRegister(digitalPinToPort(clockPin));
u8g_bitData = digitalPinToBitMask(dataPin);
u8g_bitClock = digitalPinToBitMask(clockPin);
u8g_bitNotClock = u8g_bitClock;
u8g_bitNotClock ^= 0x0ff;
u8g_bitNotData = u8g_bitData;
u8g_bitNotData ^= 0x0ff;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) U8G_NOINLINE;
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
uint8_t bitData = u8g_bitData;
uint8_t bitNotData = u8g_bitNotData;
uint8_t bitClock = u8g_bitClock;
uint8_t bitNotClock = u8g_bitNotClock;
volatile uint8_t *outData = u8g_outData;
volatile uint8_t *outClock = u8g_outClock;
U8G_ATOMIC_START();
do
{
if ( val & 128 )
*outData |= bitData;
else
*outData &= bitNotData;
*outClock |= bitClock;
val <<= 1;
cnt--;
*outClock &= bitNotClock;
} while( cnt != 0 );
U8G_ATOMIC_END();
}
/*=========================================================*/
/* Arduino, Chipkit */
#elif defined(__18CXX) || defined(__PIC32MX)
uint16_t dog_bitData, dog_bitNotData;
uint16_t dog_bitClock, dog_bitNotClock;
volatile uint32_t *dog_outData;
volatile uint32_t *dog_outClock;
volatile uint32_t dog_pic32_spi_tmp;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
dog_outData = portOutputRegister(digitalPinToPort(dataPin));
dog_outClock = portOutputRegister(digitalPinToPort(clockPin));
dog_bitData = digitalPinToBitMask(dataPin);
dog_bitClock = digitalPinToBitMask(clockPin);
dog_bitNotClock = dog_bitClock;
dog_bitNotClock ^= 0x0ffff;
dog_bitNotData = dog_bitData;
dog_bitNotData ^= 0x0ffff;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t cnt = 8;
U8G_ATOMIC_START();
do
{
if ( val & 128 )
*dog_outData |= dog_bitData;
else
*dog_outData &= dog_bitNotData;
val <<= 1;
/*
There must be some delay here. However
fetching the adress dog_outClock is enough delay, so
do not place dog_outClock in a local variable. This will
break the procedure
*/
*dog_outClock |= dog_bitClock;
cnt--;
*dog_outClock &= dog_bitNotClock;
/*
little additional delay after clk pulse, done by 3x32bit reads
from I/O. Optimized for PIC32 with 80 MHz.
*/
dog_pic32_spi_tmp = *dog_outClock;
dog_pic32_spi_tmp = *dog_outClock;
dog_pic32_spi_tmp = *dog_outClock;
} while( cnt != 0 );
U8G_ATOMIC_END();
}
/*=========================================================*/
/* Arduino Due */
#elif defined(__SAM3X8E__)
/* Due */
void u8g_digital_write_sam_high(uint8_t pin)
{
PIO_Set( g_APinDescription[pin].pPort, g_APinDescription[pin].ulPin) ;
}
void u8g_digital_write_sam_low(uint8_t pin)
{
PIO_Clear( g_APinDescription[pin].pPort, g_APinDescription[pin].ulPin) ;
}
static uint8_t u8g_sam_data_pin;
static uint8_t u8g_sam_clock_pin;
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
u8g_sam_data_pin = dataPin;
u8g_sam_clock_pin = clockPin;
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
uint8_t i = 8;
do
{
if ( val & 128 )
u8g_digital_write_sam_high(u8g_sam_data_pin);
else
u8g_digital_write_sam_low(u8g_sam_data_pin);
val <<= 1;
//u8g_MicroDelay();
u8g_digital_write_sam_high(u8g_sam_clock_pin);
u8g_MicroDelay();
u8g_digital_write_sam_low(u8g_sam_clock_pin);
u8g_MicroDelay();
i--;
} while( i != 0 );
}
#else
/* empty interface */
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
{
}
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
{
}
#endif
uint8_t u8g_com_arduino_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_com_arduino_assign_pin_output_high(u8g);
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW);
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
/* issue 227 */
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_arduino_do_shift_out_msb_first( arg_val );
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_do_shift_out_msb_first(*ptr++);
// u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_arduino_do_shift_out_msb_first( u8g_pgm_read(ptr) );
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
break;
}
return 1;
}
#else /* ARDUINO */
uint8_t u8g_com_arduino_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,403 @@
/*
u8g_com_arduino_t6963.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PIN_D0 8
PIN_D1 9
PIN_D2 10
PIN_D3 11
PIN_D4 4
PIN_D5 5
PIN_D6 6
PIN_D7 7
PIN_CS 14
PIN_A0 15
PIN_RESET 16
PIN_WR 17
PIN_RD 18
u8g_InitRW8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset)
u8g_InitRW8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16)
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
*/
#include "u8g.h"
#if defined(ARDUINO)
#if ARDUINO < 100
//#include <WProgram.h>
#include <wiring_private.h>
#include <pins_arduino.h>
#else
#include <Arduino.h>
#endif
#if defined(__PIC32MX)
/* CHIPKIT PIC32 */
static volatile uint32_t *u8g_output_data_port[8];
static volatile uint32_t *u8g_input_data_port[8];
static volatile uint32_t *u8g_mode_port[8];
static uint32_t u8g_data_mask[8];
#else
static volatile uint8_t *u8g_output_data_port[8];
static volatile uint8_t *u8g_input_data_port[8];
static volatile uint8_t *u8g_mode_port[8];
static uint8_t u8g_data_mask[8];
#endif
static void u8g_com_arduino_t6963_init(u8g_t *u8g)
{
u8g_output_data_port[0] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0]));
u8g_input_data_port[0] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0]));
u8g_mode_port[0] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D0]));
u8g_data_mask[0] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D0]);
u8g_output_data_port[1] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1]));
u8g_input_data_port[1] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1]));
u8g_mode_port[1] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D1]));
u8g_data_mask[1] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D1]);
u8g_output_data_port[2] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2]));
u8g_input_data_port[2] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2]));
u8g_mode_port[2] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D2]));
u8g_data_mask[2] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D2]);
u8g_output_data_port[3] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3]));
u8g_input_data_port[3] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3]));
u8g_mode_port[3] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D3]));
u8g_data_mask[3] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D3]);
u8g_output_data_port[4] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4]));
u8g_input_data_port[4] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4]));
u8g_mode_port[4] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D4]));
u8g_data_mask[4] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D4]);
u8g_output_data_port[5] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5]));
u8g_input_data_port[5] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5]));
u8g_mode_port[5] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D5]));
u8g_data_mask[5] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D5]);
u8g_output_data_port[6] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6]));
u8g_input_data_port[6] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6]));
u8g_mode_port[6] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D6]));
u8g_data_mask[6] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D6]);
u8g_output_data_port[7] = portOutputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7]));
u8g_input_data_port[7] = portInputRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7]));
u8g_mode_port[7] = portModeRegister(digitalPinToPort(u8g->pin_list[U8G_PI_D7]));
u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]);
}
static void u8g_com_arduino_t6963_write_data_pin(uint8_t pin, uint8_t val)
{
/* no ATOMIC protection required here, this is done by calling procedure */
if ( val != 0 )
*u8g_output_data_port[pin] |= u8g_data_mask[pin];
else
*u8g_output_data_port[pin] &= ~u8g_data_mask[pin];
}
static void u8g_com_arduino_t6963_set_port_output(void)
{
uint8_t i;
U8G_ATOMIC_START();
for( i = 0; i < 8; i++ )
{
#if defined(__PIC32MX)
/* CHIPKIT PIC32 */
*u8g_mode_port[i] |= u8g_data_mask[i];
#elif defined(__AVR__)
*u8g_mode_port[i] |= u8g_data_mask[i];
#else
/* TODO: use generic Arduino API */
*u8g_mode_port[i] |= u8g_data_mask[i];
#endif
}
U8G_ATOMIC_END();
}
static void u8g_com_arduino_t6963_set_port_input(void)
{
uint8_t i;
U8G_ATOMIC_START();
for( i = 0; i < 8; i++ )
{
#if defined(__PIC32MX)
/* CHIPKIT PIC32 */
*u8g_mode_port[i] &= ~u8g_data_mask[i];
#elif defined(__AVR__)
/* avr */
*u8g_mode_port[i] &= ~u8g_data_mask[i];
*u8g_output_data_port[i] &= ~u8g_data_mask[i]; // no pullup
#else
/* TODO: use generic Arduino API */
*u8g_mode_port[i] &= ~u8g_data_mask[i];
*u8g_output_data_port[i] &= ~u8g_data_mask[i]; // no pullup
#endif
}
U8G_ATOMIC_END();
}
static void u8g_com_arduino_t6963_write(u8g_t *u8g, uint8_t val)
{
U8G_ATOMIC_START();
u8g_com_arduino_t6963_write_data_pin( 0, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 1, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 2, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 3, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 4, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 5, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 6, val&1 );
val >>= 1;
u8g_com_arduino_t6963_write_data_pin( 7, val&1 );
val >>= 1;
U8G_ATOMIC_END();
u8g_com_arduino_digital_write(u8g, U8G_PI_WR, 0);
u8g_MicroDelay(); /* 80ns, reference: t6963 datasheet */
u8g_com_arduino_digital_write(u8g, U8G_PI_WR, 1);
u8g_MicroDelay(); /* 10ns, reference: t6963 datasheet */
}
static uint8_t u8g_com_arduino_t6963_read(u8g_t *u8g)
{
uint8_t val = 0;
u8g_com_arduino_digital_write(u8g, U8G_PI_RD, 0);
u8g_MicroDelay(); /* 150ns, reference: t6963 datasheet */
U8G_ATOMIC_START();
/* only read bits 0, 1 and 3 */
if ( (*u8g_input_data_port[3] & u8g_data_mask[3]) != 0 )
val++;
val <<= 1;
val <<= 1;
if ( (*u8g_input_data_port[1] & u8g_data_mask[1]) != 0 )
val++;
val <<= 1;
if ( (*u8g_input_data_port[0] & u8g_data_mask[0]) != 0 )
val++;
U8G_ATOMIC_END();
u8g_com_arduino_digital_write(u8g, U8G_PI_RD, 1);
u8g_MicroDelay(); /* 10ns, reference: t6963 datasheet */
return val;
}
#define U8G_STATUS_TIMEOUT 50
static uint8_t u8g_com_arduino_t6963_until_01_ok(u8g_t *u8g)
{
long x;
u8g_com_arduino_t6963_set_port_input();
x = millis();
x += U8G_STATUS_TIMEOUT;
for(;;)
{
if ( (u8g_com_arduino_t6963_read(u8g) & 3) == 3 )
break;
if ( x < millis() )
return 0;
}
u8g_com_arduino_t6963_set_port_output();
return 1;
}
static uint8_t u8g_com_arduino_t6963_until_3_ok(u8g_t *u8g)
{
long x;
u8g_com_arduino_t6963_set_port_input();
x = millis();
x += U8G_STATUS_TIMEOUT;
for(;;)
{
if ( (u8g_com_arduino_t6963_read(u8g) & 8) == 8 )
break;
if ( x < millis() )
return 0;
}
u8g_com_arduino_t6963_set_port_output();
return 1;
}
static uint8_t u8g_com_arduino_t6963_write_cmd(u8g_t *u8g, uint8_t val)
{
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, 1);
if ( u8g_com_arduino_t6963_until_01_ok(u8g) == 0 )
return 0;
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, 1);
u8g_com_arduino_t6963_write(u8g, val);
return 1;
}
static uint8_t u8g_com_arduino_t6963_write_data(u8g_t *u8g, uint8_t val)
{
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, 1);
if ( u8g_com_arduino_t6963_until_01_ok(u8g) == 0 )
return 0;
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, 0);
u8g_com_arduino_t6963_write(u8g, val);
return 1;
}
static uint8_t u8g_com_arduino_t6963_write_auto_data(u8g_t *u8g, uint8_t val)
{
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, 1);
if ( u8g_com_arduino_t6963_until_3_ok(u8g) == 0 )
return 0;
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, 0);
u8g_com_arduino_t6963_write(u8g, val);
return 1;
}
uint8_t u8g_com_arduino_t6963_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g->pin_list[U8G_PI_A0_STATE] = 0;
u8g_com_arduino_t6963_init(u8g);
/* setup the RW (equal to WR) pin as output and force it to high */
if ( u8g->pin_list[U8G_PI_WR] != U8G_PIN_NONE )
{
pinMode(u8g->pin_list[U8G_PI_WR], OUTPUT);
u8g_com_arduino_digital_write(u8g, U8G_PI_WR, HIGH);
}
/* set all pins (except WR pin) */
u8g_com_arduino_assign_pin_output_high(u8g);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable, active low chip select */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
}
else
{
/* enable */
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
{
u8g_com_arduino_t6963_write_data(u8g, arg_val);
}
else
{
u8g_com_arduino_t6963_write_cmd(u8g, arg_val);
}
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
u8g_com_arduino_t6963_write_cmd(u8g, 0x0b0); /* auto write */
while( arg_val > 0 )
{
if ( u8g_com_arduino_t6963_write_auto_data(u8g, *ptr++) == 0 )
break;
arg_val--;
}
u8g_com_arduino_t6963_write_cmd(u8g, 0x0b2); /* auto reset */
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
u8g_com_arduino_t6963_write_cmd(u8g, 0x0b0); /* auto write */
while( arg_val > 0 )
{
if ( u8g_com_arduino_t6963_write_auto_data(u8g, u8g_pgm_read(ptr)) == 0 )
break;
ptr++;
arg_val--;
}
u8g_com_arduino_t6963_write_cmd(u8g, 0x0b2); /* auto reset */
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 1) or data mode (arg_val = 0) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
//u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val);
break;
case U8G_COM_MSG_RESET:
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_arduino_t6963_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,206 @@
/*
u8g_com_arduino_uc_i2c.c
com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant
I2C protocol
ToDo: Rename this to u8g_com_avr_ssd_i2c.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Special pin usage:
U8G_PI_I2C_OPTION additional options
U8G_PI_A0_STATE used to store the last value of the command/data register selection
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
U8G_PI_SCL clock line (NOT USED)
U8G_PI_SDA data line (NOT USED)
U8G_PI_RESET reset line (currently disabled, see below)
Protocol:
SLA, Cmd/Data Selection, Arguments
The command/data register is selected by a special instruction byte, which is sent after SLA
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
*/
#include "u8g.h"
#if defined(U8G_WITH_PINLIST)
#define DOGM240_SLA_CMD (0x38*2)
#define DOGM240_SLA_DATA (0x39*2)
uint8_t u8g_com_arduino_uc_start_sequence(u8g_t *u8g)
{
/* are we requested to set the a0 state? */
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
return 1;
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
{
if ( u8g_i2c_start(DOGM240_SLA_CMD) == 0 )
return 0;
}
else
{
if ( u8g_i2c_start(DOGM240_SLA_DATA) == 0 )
return 0;
}
u8g->pin_list[U8G_PI_SET_A0] = 0;
return 1;
}
uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
//u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
//u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
/* Currently disabled, but it could be enable. Previous restrictions have been removed */
/* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */
break;
case U8G_COM_MSG_CHIP_SELECT:
u8g->pin_list[U8G_PI_A0_STATE] = 0;
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
if ( arg_val == 0 )
{
/* disable chip, send stop condition */
u8g_i2c_stop();
}
else
{
/* enable, do nothing: any byte writing will trigger the i2c start */
}
break;
case U8G_COM_MSG_WRITE_BYTE:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
if ( u8g_i2c_send_byte(arg_val) == 0 )
return u8g_i2c_stop(), 0;
// u8g_i2c_stop();
break;
case U8G_COM_MSG_WRITE_SEQ:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
if ( u8g_i2c_send_byte(*ptr++) == 0 )
return u8g_i2c_stop(), 0;
arg_val--;
}
}
// u8g_i2c_stop();
break;
case U8G_COM_MSG_WRITE_SEQ_P:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
return 0;
ptr++;
arg_val--;
}
}
// u8g_i2c_stop();
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
#ifdef OLD_CODE
if ( i2c_state != 0 )
{
u8g_i2c_stop();
i2c_state = 0;
}
if ( u8g_com_arduino_uc_start_sequence(arg_val) == 0 )
return 0;
/* setup bus, might be a repeated start */
/*
if ( u8g_i2c_start(I2C_SLA) == 0 )
return 0;
if ( arg_val == 0 )
{
i2c_state = 1;
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
return 0;
}
else
{
i2c_state = 2;
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
return 0;
}
*/
#endif
break;
}
return 1;
}
#else /* defined(U8G_WITH_PINLIST) */
uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* defined(U8G_WITH_PINLIST) */

@ -0,0 +1,188 @@
/*
u8g_com_atmega_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Assumes, that
MOSI is at PORTB, Pin 3
and
SCK is at PORTB, Pin 5
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START()
U8G_ATOMIC_END()
*/
#include "u8g.h"
#if defined(__AVR__)
#define U8G_ATMEGA_HW_SPI
/* remove the definition for attiny */
#if __AVR_ARCH__ == 2
#undef U8G_ATMEGA_HW_SPI
#endif
#if __AVR_ARCH__ == 25
#undef U8G_ATMEGA_HW_SPI
#endif
#endif
#if defined(U8G_ATMEGA_HW_SPI)
#include <avr/interrupt.h>
#include <avr/io.h>
static uint8_t u8g_atmega_spi_out(uint8_t data)
{
/* unsigned char x = 100; */
/* send data */
SPDR = data;
/* wait for transmission */
while (!(SPSR & (1<<SPIF)))
;
/* clear the SPIF flag by reading SPDR */
return SPDR;
}
uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_CS);
u8g_SetPIOutput(u8g, U8G_PI_A0);
u8g_SetPIOutput(u8g, U8G_PI_RESET);
U8G_ATOMIC_START();
DDRB |= _BV(3); /* D0, MOSI */
DDRB |= _BV(5); /* SCK */
DDRB |= _BV(2); /* slave select */
PORTB &= ~_BV(3); /* D0, MOSI = 0 */
PORTB &= ~_BV(5); /* SCK = 0 */
U8G_ATOMIC_END();
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
/*
SPR1 SPR0
0 0 fclk/4 x
0 1 fclk/16
1 0 fclk/64
1 1 fclk/128
*/
SPCR = 0;
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(0<<CPOL)|(0<<CPHA);
#ifdef U8G_HW_SPI_2X
SPSR = (1 << SPI2X); /* double speed, issue 89 */
#endif
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
}
else
{
PORTB &= ~_BV(5); /* SCK = 0 */
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */
}
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_atmega_spi_out(arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_atmega_spi_out(*ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_atmega_spi_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
#else
uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,183 @@
/*
u8g_com_atmega_parallel.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PIN_D0 8
PIN_D1 9
PIN_D2 10
PIN_D3 11
PIN_D4 4
PIN_D5 5
PIN_D6 6
PIN_D7 7
PIN_CS1 14
PIN_CS2 15
PIN_RW 16
PIN_DI 17
PIN_EN 18
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
*/
#include "u8g.h"
#if defined(__AVR__)
static void u8g_com_atmega_parallel_write(u8g_t *u8g, uint8_t val) U8G_NOINLINE;
static void u8g_com_atmega_parallel_write(u8g_t *u8g, uint8_t val)
{
u8g_SetPILevel(u8g, U8G_PI_D0, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D1, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D2, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D3, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D4, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D5, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D6, val&1);
val >>= 1;
u8g_SetPILevel(u8g, U8G_PI_D7, val&1);
/* EN cycle time must be 1 micro second */
u8g_SetPILevel(u8g, U8G_PI_EN, 1);
u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */
u8g_SetPILevel(u8g, U8G_PI_EN, 0);
u8g_10MicroDelay(); /* ST7920 commands: 72us */
u8g_10MicroDelay(); /* ST7920 commands: 72us */
}
uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
/* setup the RW pin as output and force it to low */
u8g_SetPIOutput(u8g, U8G_PI_RW);
u8g_SetPILevel(u8g, U8G_PI_RW, 0);
u8g_SetPIOutput(u8g, U8G_PI_D0);
u8g_SetPIOutput(u8g, U8G_PI_D1);
u8g_SetPIOutput(u8g, U8G_PI_D2);
u8g_SetPIOutput(u8g, U8G_PI_D3);
u8g_SetPIOutput(u8g, U8G_PI_D4);
u8g_SetPIOutput(u8g, U8G_PI_D5);
u8g_SetPIOutput(u8g, U8G_PI_D6);
u8g_SetPIOutput(u8g, U8G_PI_D7);
u8g_SetPIOutput(u8g, U8G_PI_EN);
u8g_SetPIOutput(u8g, U8G_PI_CS1);
u8g_SetPIOutput(u8g, U8G_PI_CS2);
u8g_SetPIOutput(u8g, U8G_PI_DI);
u8g_SetPILevel(u8g, U8G_PI_CS1, 1);
u8g_SetPILevel(u8g, U8G_PI_CS2, 1);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_SetPILevel(u8g, U8G_PI_CS1, 1);
u8g_SetPILevel(u8g, U8G_PI_CS2, 1);
}
else if ( arg_val == 1 )
{
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS1, 0);
u8g_SetPILevel(u8g, U8G_PI_CS2, 1);
}
else if ( arg_val == 2 )
{
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS1, 1);
u8g_SetPILevel(u8g, U8G_PI_CS2, 0);
}
else
{
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS1, 0);
u8g_SetPILevel(u8g, U8G_PI_CS2, 0);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_atmega_parallel_write(u8g, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_atmega_parallel_write(u8g, *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_atmega_parallel_write(u8g, u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel(u8g, U8G_PI_DI, arg_val);
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif /* ARDUINO */

@ -0,0 +1,216 @@
/*
u8g_com_atmega_st7920_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
A special SPI interface for ST7920 controller with HW SPI Support
Assumes, that
MOSI is at PORTB, Pin 3
and
SCK is at PORTB, Pin 5
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START()
U8G_ATOMIC_END()
*/
#include "u8g.h"
#if defined(__AVR__)
#define U8G_ATMEGA_HW_SPI
/* remove the definition for attiny */
#if __AVR_ARCH__ == 2
#undef U8G_ATMEGA_HW_SPI
#endif
#if __AVR_ARCH__ == 25
#undef U8G_ATMEGA_HW_SPI
#endif
#endif
#if defined(U8G_ATMEGA_HW_SPI)
#include <avr/interrupt.h>
#include <avr/io.h>
static uint8_t u8g_atmega_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE;
static uint8_t u8g_atmega_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val)
{
/* send data */
SPDR = val;
/* wait for transmission */
while (!(SPSR & (1<<SPIF)))
;
/* clear the SPIF flag by reading SPDR */
return SPDR;
}
static void u8g_com_atmega_st7920_write_byte_hw_spi(u8g_t *u8g, uint8_t rs, uint8_t val) U8G_NOINLINE;
static void u8g_com_atmega_st7920_write_byte_hw_spi(u8g_t *u8g, uint8_t rs, uint8_t val)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_atmega_st7920_hw_spi_shift_out(u8g, 0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_atmega_st7920_hw_spi_shift_out(u8g, 0x0fa);
}
u8g_atmega_st7920_hw_spi_shift_out(u8g, val & 0x0f0);
u8g_atmega_st7920_hw_spi_shift_out(u8g, val << 4);
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
uint8_t u8g_com_atmega_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_CS);
//u8g_SetPIOutput(u8g, U8G_PI_A0);
U8G_ATOMIC_START();
DDRB |= _BV(3); /* D0, MOSI */
DDRB |= _BV(5); /* SCK */
DDRB |= _BV(2); /* slave select */
PORTB &= ~_BV(3); /* D0, MOSI = 0 */
PORTB &= ~_BV(5); /* SCK = 0 */
U8G_ATOMIC_END();
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
/*
SPR1 SPR0
0 0 fclk/4
0 1 fclk/16
1 0 fclk/64
1 1 fclk/128
*/
SPCR = 0;
/* maybe set CPOL and CPHA to 1 */
/* 20 Dez 2012: did set CPOL and CPHA to 1 in Arduino variant! */
/* 24 Jan 2014: implemented, see also issue 221 */
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(1<<CPOL)|(1<<CPHA);
#ifdef U8G_HW_SPI_2X
SPSR = (1 << SPI2X); /* double speed, issue 89 */
#endif
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable, note: the st7920 has an active high chip select */
u8g_SetPILevel(u8g, U8G_PI_CS, 0);
}
else
{
/* u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); */
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS, 1); /* CS = 1 (high active) */
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_atmega_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], arg_val);
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_atmega_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_atmega_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr));
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
#else
uint8_t u8g_com_atmega_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,170 @@
/*
u8g_com_atmega_st7920_spi.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
A special SPI interface for ST7920 controller
*/
#include "u8g.h"
#if defined(__AVR__)
static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE;
static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val)
{
uint8_t i = 8;
do
{
u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 );
val <<= 1;
u8g_SetPILevel(u8g, U8G_PI_SCK, 1 );
u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */
u8g_SetPILevel(u8g, U8G_PI_SCK, 0 );
u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */
i--;
} while( i != 0 );
}
static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val) U8G_NOINLINE;
static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val)
{
uint8_t i;
if ( rs == 0 )
{
/* command */
u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0f8);
}
else if ( rs == 1 )
{
/* data */
u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0fa);
}
u8g_atmega_st7920_sw_spi_shift_out(u8g, val & 0x0f0);
u8g_atmega_st7920_sw_spi_shift_out(u8g, val << 4);
for( i = 0; i < 4; i++ )
u8g_10MicroDelay();
}
uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_SCK);
u8g_SetPIOutput(u8g, U8G_PI_MOSI);
/* u8g_SetPIOutput(u8g, U8G_PI_A0); */
u8g_SetPIOutput(u8g, U8G_PI_CS);
u8g_SetPIOutput(u8g, U8G_PI_RESET);
u8g_SetPILevel(u8g, U8G_PI_SCK, 0 );
u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 );
u8g_SetPILevel(u8g, U8G_PI_CS, 0 );
/* u8g_SetPILevel(u8g, U8G_PI_A0, 0); */
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable, note: the st7920 has an active high chip select */
u8g_SetPILevel(u8g, U8G_PI_CS, 0);
}
else
{
/* u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); */
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS, 1); /* CS = 1 (high active) */
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], arg_val);
u8g->pin_list[U8G_PI_A0_STATE] = 2;
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
u8g->pin_list[U8G_PI_A0_STATE] = 2;
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr));
u8g->pin_list[U8G_PI_A0_STATE] = 2;
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
#else
uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,141 @@
/*
u8g_com_atmega_sw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#if defined(__AVR__)
static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE;
static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val)
{
uint8_t i = 8;
do
{
u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 );
val <<= 1;
u8g_SetPILevel(u8g, U8G_PI_SCK, 1 );
u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */
u8g_SetPILevel(u8g, U8G_PI_SCK, 0 );
u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */
i--;
} while( i != 0 );
}
uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_SCK);
u8g_SetPIOutput(u8g, U8G_PI_MOSI);
u8g_SetPIOutput(u8g, U8G_PI_A0);
u8g_SetPIOutput(u8g, U8G_PI_CS);
u8g_SetPIOutput(u8g, U8G_PI_RESET);
u8g_SetPILevel(u8g, U8G_PI_SCK, 0 );
u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 );
u8g_SetPILevel(u8g, U8G_PI_CS, 1 );
u8g_SetPILevel(u8g, U8G_PI_A0, 0);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
}
else
{
u8g_SetPILevel(u8g, U8G_PI_SCK, 0 );
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */
}
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_atmega_sw_spi_shift_out(u8g, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_atmega_sw_spi_shift_out(u8g, *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
}
return 1;
}
#else
uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,643 @@
/*
u8g_com_i2c.c
generic i2c interface
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
//#define U8G_I2C_WITH_NO_ACK
static uint8_t u8g_i2c_err_code;
static uint8_t u8g_i2c_opt; /* U8G_I2C_OPT_NO_ACK, SAM: U8G_I2C_OPT_DEV_1 */
/*
position values
1: start condition
2: sla transfer
*/
static uint8_t u8g_i2c_err_pos;
void u8g_i2c_clear_error(void)
{
u8g_i2c_err_code = U8G_I2C_ERR_NONE;
u8g_i2c_err_pos = 0;
}
uint8_t u8g_i2c_get_error(void)
{
return u8g_i2c_err_code;
}
uint8_t u8g_i2c_get_err_pos(void)
{
return u8g_i2c_err_pos;
}
#if defined(__AVR__)
static void u8g_i2c_set_error(uint8_t code, uint8_t pos)
{
if ( u8g_i2c_err_code > 0 )
return;
u8g_i2c_err_code |= code;
u8g_i2c_err_pos = pos;
}
#define U8G_ATMEGA_HW_TWI
/* remove the definition for attiny */
#if __AVR_ARCH__ == 2
#undef U8G_ATMEGA_HW_TWI
#endif
#if __AVR_ARCH__ == 25
#undef U8G_ATMEGA_HW_TWI
#endif
#endif
#if defined(U8G_ATMEGA_HW_TWI)
#include <avr/io.h>
#include <util/twi.h>
void u8g_i2c_init(uint8_t options)
{
/*
TWBR: bit rate register
TWSR: status register (contains preselector bits)
prescalar
0 1
1 4
2 16
3 64
f = F_CPU/(16+2*TWBR*prescalar)
F_CPU = 16MHz
TWBR = 152;
TWSR = 0;
--> 50KHz
TWBR = 72;
TWSR = 0;
--> 100KHz
TWBR = 12;
TWSR = 0;
--> 400KHz
F_CPU/(2*100000)-8 --> calculate TWBR value for 100KHz
*/
u8g_i2c_opt = options;
TWSR = 0;
if ( options & U8G_I2C_OPT_FAST )
{
TWBR = F_CPU/(2*400000)-8;
}
else
{
TWBR = F_CPU/(2*100000)-8;
}
u8g_i2c_clear_error();
}
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
{
volatile uint16_t cnt = 2000; /* timout value should be > 280 for 50KHz Bus and 16 Mhz CPU, however the start condition might need longer */
while( !(TWCR & mask) )
{
if ( cnt == 0 )
{
if ( u8g_i2c_opt & U8G_I2C_OPT_NO_ACK )
{
return 1; /* all ok */
}
else
{
u8g_i2c_set_error(U8G_I2C_ERR_TIMEOUT, pos);
return 0; /* error */
}
}
cnt--;
}
return 1; /* all ok */
}
/* sla includes all 8 bits (with r/w bit), assums master transmit */
uint8_t u8g_i2c_start(uint8_t sla)
{
register uint8_t status;
/* send start */
TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);
/* wait */
if ( u8g_i2c_wait(_BV(TWINT), 1) == 0 )
return 0;
status = TW_STATUS;
/* check status after start */
if ( status != TW_START && status != TW_REP_START )
{
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 1);
return 0;
}
/* set slave address */
TWDR = sla;
/* enable sla transfer */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait */
if ( u8g_i2c_wait(_BV(TWINT), 2) == 0 )
return 0;
if ( u8g_i2c_opt & U8G_I2C_OPT_NO_ACK )
{
/* do not check for ACK */
}
else
{
status = TW_STATUS;
/* check status after sla */
if ( status != TW_MT_SLA_ACK )
{
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 2);
return 0;
}
}
return 1;
}
uint8_t u8g_i2c_send_byte(uint8_t data)
{
register uint8_t status;
TWDR = data;
TWCR = _BV(TWINT) | _BV(TWEN);
if ( u8g_i2c_wait(_BV(TWINT), 3) == 0 )
return 0;
if ( u8g_i2c_opt & U8G_I2C_OPT_NO_ACK )
{
/* do not check for ACK */
}
else
{
status = TW_STATUS;
if ( status != TW_MT_DATA_ACK )
{
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 3);
return 0;
}
}
return 1;
}
void u8g_i2c_stop(void)
{
/* write stop */
TWCR = _BV(TWINT) | _BV(TWEN) | _BV(TWSTO);
/* no error is checked for the stop condition */
u8g_i2c_wait(_BV(TWSTO), 4);
}
/*
void twi_send(uint8_t adr, uint8_t data1, uint8_t data2)
{
u8g_i2c_start(adr<<1);
u8g_i2c_send_byte(data1);
u8g_i2c_send_byte(data2);
u8g_i2c_stop();
}
*/
#elif defined(ARDUINO) && defined(__SAM3X8E__)
/* Arduino Due */
#include "Arduino.h"
#include "sam.h"
/*
Controller
TWI0 TWCK0 PA18 A DUE PCB: SCL1
TWI0 TWD0 PA17 A DUE PCB: SDA1
TWI1 TWCK1 PB13 A DUE PCB: SCL 21
TWI1 TWD1 PB12 A DUE PCB: SDA 20
Arduino definitions
#define PIN_WIRE_SDA (20u)
#define PIN_WIRE_SCL (21u)
#define WIRE_INTERFACE TWI1
#define WIRE_INTERFACE_ID ID_TWI1
#define WIRE_ISR_HANDLER TWI1_Handler
#define PIN_WIRE1_SDA (70u)
#define PIN_WIRE1_SCL (71u)
#define WIRE1_INTERFACE TWI0
#define WIRE1_INTERFACE_ID ID_TWI0
#define WIRE1_ISR_HANDLER TWI0_Handler
*/
static void i2c_400KHz_delay(void)
{
/* should be at least 4 */
/* should be 5 for 100KHz transfer speed */
/*
Arduino Due
0x NOP: 470KHz
4x NOP: 450KHz
8x NOP: 430KHz
16x NOP: 400KHz
*/
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
}
static void i2c_100KHz_delay(void)
{
/*
1x u8g_MicroDelay() ca. 130KHz
2x u8g_MicroDelay() ca. 80KHz
*/
u8g_MicroDelay();
u8g_MicroDelay();
}
uint32_t i2c_started = 0;
uint32_t i2c_scl_pin = 0;
uint32_t i2c_sda_pin = 0;
void (*i2c_delay)(void) = i2c_100KHz_delay;
const PinDescription *i2c_scl_pin_desc;
const PinDescription *i2c_sda_pin_desc;
/* maybe this can be optimized */
static void i2c_init(void)
{
i2c_sda_pin_desc = &(g_APinDescription[i2c_sda_pin]);
i2c_scl_pin_desc = &(g_APinDescription[i2c_scl_pin]);
pinMode(i2c_sda_pin, OUTPUT);
digitalWrite(i2c_sda_pin, HIGH);
pinMode(i2c_scl_pin, OUTPUT);
digitalWrite(i2c_scl_pin, HIGH);
PIO_Configure( i2c_sda_pin_desc->pPort, PIO_OUTPUT_0, i2c_sda_pin_desc->ulPin, PIO_OPENDRAIN );
PIO_Configure( i2c_scl_pin_desc->pPort, PIO_OUTPUT_0, i2c_scl_pin_desc->ulPin, PIO_OPENDRAIN );
PIO_Clear( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin) ;
PIO_Clear( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin) ;
PIO_Configure( i2c_sda_pin_desc->pPort, PIO_INPUT, i2c_sda_pin_desc->ulPin, PIO_DEFAULT ) ;
PIO_Configure( i2c_scl_pin_desc->pPort, PIO_INPUT, i2c_scl_pin_desc->ulPin, PIO_DEFAULT ) ;
i2c_delay();
}
/* actually, the scl line is not observed, so this procedure does not return a value */
static void i2c_read_scl_and_delay(void)
{
uint32_t dwMask = i2c_scl_pin_desc->ulPin;
//PIO_Configure( i2c_scl_pin_desc->pPort, PIO_INPUT, i2c_scl_pin_desc->ulPin, PIO_DEFAULT ) ;
//PIO_SetInput( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin, PIO_DEFAULT ) ;
/* set as input */
i2c_scl_pin_desc->pPort->PIO_ODR = dwMask ;
i2c_scl_pin_desc->pPort->PIO_PER = dwMask ;
i2c_delay();
}
static void i2c_clear_scl(void)
{
uint32_t dwMask = i2c_scl_pin_desc->ulPin;
/* set open collector and drive low */
//PIO_Configure( i2c_scl_pin_desc->pPort, PIO_OUTPUT_0, i2c_scl_pin_desc->ulPin, PIO_OPENDRAIN );
//PIO_SetOutput( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin, 0, 1, 0);
/* open drain, zero default output */
i2c_scl_pin_desc->pPort->PIO_MDER = dwMask;
i2c_scl_pin_desc->pPort->PIO_CODR = dwMask;
i2c_scl_pin_desc->pPort->PIO_OER = dwMask;
i2c_scl_pin_desc->pPort->PIO_PER = dwMask;
//PIO_Clear( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin) ;
}
static uint8_t i2c_read_sda(void)
{
uint32_t dwMask = i2c_sda_pin_desc->ulPin;
//PIO_Configure( i2c_sda_pin_desc->pPort, PIO_INPUT, i2c_sda_pin_desc->ulPin, PIO_DEFAULT ) ;
//PIO_SetInput( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin, PIO_DEFAULT ) ;
/* set as input */
i2c_sda_pin_desc->pPort->PIO_ODR = dwMask ;
i2c_sda_pin_desc->pPort->PIO_PER = dwMask ;
return 1;
}
static void i2c_clear_sda(void)
{
uint32_t dwMask = i2c_sda_pin_desc->ulPin;
/* set open collector and drive low */
//PIO_Configure( i2c_sda_pin_desc->pPort, PIO_OUTPUT_0, i2c_sda_pin_desc->ulPin, PIO_OPENDRAIN );
//PIO_SetOutput( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin, 0, 1, 0);
/* open drain, zero default output */
i2c_sda_pin_desc->pPort->PIO_MDER = dwMask ;
i2c_sda_pin_desc->pPort->PIO_CODR = dwMask ;
i2c_sda_pin_desc->pPort->PIO_OER = dwMask ;
i2c_sda_pin_desc->pPort->PIO_PER = dwMask ;
//PIO_Clear( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin) ;
}
static void i2c_start(void)
{
if ( i2c_started != 0 )
{
/* if already started: do restart */
i2c_read_sda(); /* SDA = 1 */
i2c_delay();
i2c_read_scl_and_delay();
}
i2c_read_sda();
/*
if (i2c_read_sda() == 0)
{
// do something because arbitration is lost
}
*/
/* send the start condition, both lines go from 1 to 0 */
i2c_clear_sda();
i2c_delay();
i2c_clear_scl();
i2c_started = 1;
}
static void i2c_stop(void)
{
/* set SDA to 0 */
i2c_clear_sda();
i2c_delay();
/* now release all lines */
i2c_read_scl_and_delay();
/* set SDA to 1 */
i2c_read_sda();
i2c_delay();
i2c_started = 0;
}
static void i2c_write_bit(uint8_t val)
{
if (val)
i2c_read_sda();
else
i2c_clear_sda();
i2c_delay();
i2c_read_scl_and_delay();
i2c_clear_scl();
}
static uint8_t i2c_read_bit(void)
{
uint8_t val;
/* do not drive SDA */
i2c_read_sda();
i2c_delay();
i2c_read_scl_and_delay();
val = i2c_read_sda();
i2c_delay();
i2c_clear_scl();
return val;
}
static uint8_t i2c_write_byte(uint8_t b)
{
i2c_write_bit(b & 128);
i2c_write_bit(b & 64);
i2c_write_bit(b & 32);
i2c_write_bit(b & 16);
i2c_write_bit(b & 8);
i2c_write_bit(b & 4);
i2c_write_bit(b & 2);
i2c_write_bit(b & 1);
/* read ack from client */
/* 0: ack was given by client */
/* 1: nothing happend during ack cycle */
return i2c_read_bit();
}
void u8g_i2c_init(uint8_t options)
{
u8g_i2c_opt = options;
u8g_i2c_clear_error();
if ( u8g_i2c_opt & U8G_I2C_OPT_FAST )
{
i2c_delay = i2c_400KHz_delay;
}
else
{
i2c_delay = i2c_100KHz_delay;
}
if ( u8g_i2c_opt & U8G_I2C_OPT_DEV_1 )
{
i2c_scl_pin = PIN_WIRE1_SCL;
i2c_sda_pin = PIN_WIRE1_SDA;
//REG_PIOA_PDR = PIO_PB12A_TWD1 | PIO_PB13A_TWCK1;
}
else
{
i2c_scl_pin = PIN_WIRE_SCL;
i2c_sda_pin = PIN_WIRE_SDA;
//REG_PIOA_PDR = PIO_PA17A_TWD0 | PIO_PA18A_TWCK0;
}
i2c_init();
}
/* sla includes also the r/w bit */
uint8_t u8g_i2c_start(uint8_t sla)
{
i2c_start();
i2c_write_byte(sla);
return 1;
}
uint8_t u8g_i2c_send_byte(uint8_t data)
{
return i2c_write_byte(data);
}
void u8g_i2c_stop(void)
{
i2c_stop();
}
#elif defined(U8G_RASPBERRY_PI)
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define I2C_SLA 0x3c
static int fd=-1;
static uint8_t i2cMode = 0;
void u8g_i2c_init(uint8_t options) {
u8g_i2c_clear_error();
u8g_i2c_opt = options;
if (wiringPiSetup() == -1) {
printf("wiringPi-Error\n");
exit(1);
}
fd = wiringPiI2CSetup(I2C_SLA);
if (fd < 0) {
printf ("Unable to open I2C device 0: %s\n", strerror (errno)) ;
exit (1) ;
}
//u8g_SetPIOutput(u8g, U8G_PI_RESET);
//u8g_SetPIOutput(u8g, U8G_PI_A0);
}
uint8_t u8g_i2c_start(uint8_t sla) {
u8g_i2c_send_mode(0);
return 1;
}
void u8g_i2c_stop(void) {
}
uint8_t u8g_i2c_send_mode(uint8_t mode) {
i2cMode = mode;
}
uint8_t u8g_i2c_send_byte(uint8_t data) {
wiringPiI2CWriteReg8(fd, i2cMode, data);
return 1;
}
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
{
return 1;
}
#else
/* empty interface */
void u8g_i2c_init(uint8_t options)
{
u8g_i2c_clear_error();
}
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
{
return 1;
}
uint8_t u8g_i2c_start(uint8_t sla)
{
return 1;
}
uint8_t u8g_i2c_send_byte(uint8_t data)
{
return 1;
}
void u8g_i2c_stop(void)
{
}
#endif

@ -0,0 +1,374 @@
/*
u8g_com_io.c
abstraction layer for low level i/o
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START();
U8G_ATOMIC_END();
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos) Convert to internal number: AVR: port*8+bitpos, ARM: port*16+bitpos
void u8g_SetPinOutput(uint8_t internal_pin_number)
void u8g_SetPinInput(uint8_t internal_pin_number)
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
*/
#include "u8g.h"
#if defined(__AVR__)
#include <avr/interrupt.h>
#include <avr/io.h>
typedef volatile uint8_t * IO_PTR;
/* create internal pin number */
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)
{
port <<= 3;
port += bitpos;
return port;
}
const IO_PTR u8g_avr_ddr_P[] PROGMEM = {
#ifdef DDRA
&DDRA,
#else
0,
#endif
&DDRB,
#ifdef DDRC
&DDRC,
#ifdef DDRD
&DDRD,
#ifdef DDRE
&DDRE,
#ifdef DDRF
&DDRF,
#ifdef DDRG
&DDRG,
#ifdef DDRH
&DDRH,
#endif
#endif
#endif
#endif
#endif
#endif
};
const IO_PTR u8g_avr_port_P[] PROGMEM = {
#ifdef PORTA
&PORTA,
#else
0,
#endif
&PORTB,
#ifdef PORTC
&PORTC,
#ifdef PORTD
&PORTD,
#ifdef PORTE
&PORTE,
#ifdef PORTF
&PORTF,
#ifdef PORTG
&PORTG,
#ifdef PORTH
&PORTH,
#endif
#endif
#endif
#endif
#endif
#endif
};
const IO_PTR u8g_avr_pin_P[] PROGMEM = {
#ifdef PINA
&PINA,
#else
0,
#endif
&PINB,
#ifdef PINC
&PINC,
#ifdef PIND
&PIND,
#ifdef PINE
&PINE,
#ifdef PINF
&PINF,
#ifdef PING
&PING,
#ifdef PINH
&PINH,
#endif
#endif
#endif
#endif
#endif
#endif
};
static volatile uint8_t *u8g_get_avr_io_ptr(const IO_PTR *base, uint8_t offset)
{
volatile uint8_t * tmp;
base += offset;
memcpy_P(&tmp, base, sizeof(volatile uint8_t * PROGMEM));
return tmp;
}
/* set direction to output of the specified pin (internal pin number) */
void u8g_SetPinOutput(uint8_t internal_pin_number)
{
*u8g_get_avr_io_ptr(u8g_avr_ddr_P, internal_pin_number>>3) |= _BV(internal_pin_number&7);
}
void u8g_SetPinInput(uint8_t internal_pin_number)
{
*u8g_get_avr_io_ptr(u8g_avr_ddr_P, internal_pin_number>>3) &= ~_BV(internal_pin_number&7);
}
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
{
volatile uint8_t * tmp = u8g_get_avr_io_ptr(u8g_avr_port_P, internal_pin_number>>3);
if ( level == 0 )
{
U8G_ATOMIC_AND(tmp, ~_BV(internal_pin_number&7));
// *tmp &= ~_BV(internal_pin_number&7);
}
else
{
U8G_ATOMIC_OR(tmp, _BV(internal_pin_number&7));
//*tmp |= _BV(internal_pin_number&7);
}
}
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
{
volatile uint8_t * tmp = u8g_get_avr_io_ptr(u8g_avr_pin_P, internal_pin_number>>3);
if ( ((*tmp) & _BV(internal_pin_number&7)) != 0 )
return 1;
return 0;
}
#elif defined (__MSP430__)
#include <msp430.h>
typedef volatile uint8_t * IO_PTR;
// MSP430 F5XXX / F6XXX series.
const IO_PTR u8g_msp_ddr_P[] PROGMEM = {
&P1DIR
,&P2DIR
,&P3DIR
,&P4DIR
,&P5DIR
,&P6DIR
,&P7DIR
,&P8DIR
#if defined (__MSP430_HAS_PORT9_R__)
,&P9DIR
#if defined (__MSP430_HAS_PORT10_R__)
,&P10DIR
#endif
#endif
};
const IO_PTR u8g_msp_port_P[] PROGMEM = {
&P1OUT
,&P2OUT
,&P3OUT
,&P4OUT
,&P5OUT
,&P6OUT
,&P7OUT
,&P8OUT
#if defined (__MSP430_HAS_PORT9_R__)
,&P9OUT
#if defined (__MSP430_HAS_PORT10_R__)
,&P10OUT
#endif
#endif
};
const IO_PTR u8g_msp_pin_P[] PROGMEM = {
&P1IN
,&P2IN
,&P3IN
,&P4IN
,&P5IN
,&P6IN
,&P7IN
,&P8IN
#if defined (__MSP430_HAS_PORT9_R__)
,&P9IN
#if defined (__MSP430_HAS_PORT10_R__)
,&P10IN
#endif
#endif
};
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)
{
port <<= 3;
port += bitpos;
return port;
}
void u8g_SetPinOutput(uint8_t internal_pin_number)
{
uint8_t port = (internal_pin_number >> 3)-1;
uint8_t output = 1 << (internal_pin_number & 0x07);
*u8g_msp_ddr_P[port] |= output;
}
void u8g_SetPinInput(uint8_t internal_pin_number)
{
uint8_t port = (internal_pin_number >> 3)-1;
*u8g_msp_ddr_P[port] &= ~(1 << (internal_pin_number & 0x07));
}
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
{
uint8_t port = (internal_pin_number >> 3)-1;
if (level == 0)
{
*u8g_msp_port_P[port] &= ~(1 << (internal_pin_number & 0x07));
}
else
{
*u8g_msp_port_P[port]|= (1 << (internal_pin_number & 0x07));
}
}
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
{
uint8_t port = (internal_pin_number >> 3)-1;
uint8_t tmp = *u8g_msp_pin_P[port];
if (tmp & (1 << (internal_pin_number & 0x07)))
{
return 1;
}
return 0;
}
#elif defined(U8G_RASPBERRY_PI)
#include <wiringPi.h>
//#include "/usr/local/include/wiringPi.h"
void u8g_SetPinOutput(uint8_t internal_pin_number) {
pinMode(internal_pin_number, OUTPUT);
}
void u8g_SetPinInput(uint8_t internal_pin_number) {
pinMode(internal_pin_number, INPUT);
}
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level) {
digitalWrite(internal_pin_number, level);
}
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number) {
return digitalRead(internal_pin_number);
}
#else
/* convert "port" and "bitpos" to internal pin number */
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)
{
port <<= 3;
port += bitpos;
return port;
}
void u8g_SetPinOutput(uint8_t internal_pin_number)
{
}
void u8g_SetPinInput(uint8_t internal_pin_number)
{
}
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
{
}
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
{
return 0;
}
#endif
#if defined(U8G_WITH_PINLIST)
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi)
{
uint8_t pin;
pin = u8g->pin_list[pi];
if ( pin != U8G_PIN_NONE )
u8g_SetPinOutput(pin);
}
void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level)
{
uint8_t pin;
pin = u8g->pin_list[pi];
if ( pin != U8G_PIN_NONE )
u8g_SetPinLevel(pin, level);
}
#else /* defined(U8G_WITH_PINLIST) */
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi)
{
}
void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level)
{
}
#endif /* defined(U8G_WITH_PINLIST) */

@ -0,0 +1,221 @@
/*
u8g_com_msp430_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#if defined(__MSP430__)
#define U8G_MSP430_HW_SPI
#endif
#if defined(U8G_MSP430_HW_SPI)
#include <msp430.h>
#ifndef F_CPU
#error "Please specifiy actual master clock using F_CPU in HZ"
#endif
#ifndef F_SPI
#define F_SPI 1000000UL
#endif
#define U8G_USE_USCIA0 1
#define U8G_USE_USCIB0 2
#define U8G_USE_USCIA1 3
#define U8G_USE_USCIB1 4
#define U8G_USE_USCIA2 5
#define U8G_USE_USCIB2 6
#define U8G_USE_USCIA3 7
#define U8G_USE_USCIB3 8
#ifndef U8G_USE_USCI
#define U8G_USE_USCI U8G_USE_USCIB0
#endif
#if U8G_USE_USCI == 1
#define UCIFG UCA0IFG
#define UCTXBUF UCA0TXBUF
#define UCSTAT UCA0STAT
#define UCCTL0 UCA0CTL0
#define UCCTL1 UCA0CTL1
#define UCBR0 UCA0BR0
#define UCBR1 UCA0BR1
#elif U8G_USE_USCI == 2
#define UCIFG UCB0IFG
#define UCTXBUF UCB0TXBUF
#define UCSTAT UCB0STAT
#define UCCTL0 UCB0CTL0
#define UCCTL1 UCB0CTL1
#define UCBR0 UCB0BR0
#define UCBR1 UCB0BR1
#elif U8G_USE_USCI == 3
#define UCIFG UCA1IFG
#define UCTXBUF UCA1TXBUF
#define UCSTAT UCA1STAT
#define UCCTL0 UCA1CTL0
#define UCCTL1 UCA1CTL1
#define UCBR0 UCA1BR0
#define UCBR1 UCA1BR1
#elif U8G_USE_USCI == 4
#define UCIFG UCB1IFG
#define UCTXBUF UCB1TXBUF
#define UCSTAT UCB1STAT
#define UCCTL0 UCB1CTL0
#define UCCTL1 UCB1CTL1
#define UCBR0 UCB1BR0
#define UCBR1 UCB1BR1
#elif U8G_USE_USCI == 5
#define UCIFG UCA2IFG
#define UCTXBUF UCA2TXBUF
#define UCSTAT UCA2STAT
#define UCCTL0 UCA2CTL0
#define UCCTL1 UCA2CTL1
#define UCBR0 UCA2BR0
#define UCBR1 UCA2BR1
#elif U8G_USE_USCI == 6
#define UCIFG UCB2IFG
#define UCTXBUF UCB2TXBUF
#define UCSTAT UCB2STAT
#define UCCTL0 UCB2CTL0
#define UCCTL1 UCB2CTL1
#define UCBR0 UCB2BR0
#define UCBR1 UCB2BR1
#elif U8G_USE_USCI == 7
#define UCIFG UCA3IFG
#define UCTXBUF UCA3TXBUF
#define UCSTAT UCA3STAT
#define UCCTL0 UCA3CTL0
#define UCCTL1 UCA3CTL1
#define UCBR0 UCA3BR0
#define UCBR1 UCA3BR1
#elif U8G_USE_USCI == 8
#define UCIFG UCB3IFG
#define UCTXBUF UCB3TXBUF
#define UCSTAT UCB3STAT
#define UCCTL0 UCB3CTL0
#define UCCTL1 UCB3CTL1
#define UCBR0 UCB3BR0
#define UCBR1 UCB3BR1
#endif
inline void u8g_msp430_spi_out(uint8_t data)
{
while (!(UCIFG&UCTXIFG));
UCTXBUF = data;
}
uint8_t u8g_com_msp430_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
/*
* on MSP430 you need to set PSEL alternative function which
* may not be required on other MCU's - should be handled
* by a low level u8g_SetPinAlternate(pin_number)...
*/
UCCTL1 |= UCSWRST; // **Put state machine in reset**
UCCTL0 |= UCMST|UCSYNC|UCCKPL|UCMSB; // 3-pin, 8-bit SPI master Clock polarity high, MSB
UCCTL1 |= UCSSEL_2; // SMCLK
UCBR0 = (unsigned char)(F_CPU/F_SPI); //
UCBR1 = 0; //
UCCTL1 &= ~UCSWRST; // **Initialize USCI state machine**
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
u8g_SetPILevel(u8g, U8G_PI_A0, 1);
u8g_SetPILevel(u8g, U8G_PI_RESET, 1);
u8g_SetPIOutput(u8g, U8G_PI_CS);
u8g_SetPIOutput(u8g, U8G_PI_A0);
u8g_SetPIOutput(u8g, U8G_PI_RESET);
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
u8g_SetPILevel(u8g, U8G_PI_CS, (arg_val ? 0 : 1));
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_msp430_spi_out(arg_val);
while ((UCSTAT&UCBUSY));
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_msp430_spi_out(*ptr++);
arg_val--;
}
while ((UCSTAT&UCBUSY));
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_msp430_spi_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
while ((UCSTAT&UCBUSY));
}
break;
}
return 1;
}
#else
uint8_t u8g_com_msp430_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,63 @@
/*
u8g_com_null.c
communication null device
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_CHIP_SELECT:
/* arg_val contains the chip number, which should be enabled */
break;
case U8G_COM_MSG_WRITE_BYTE:
break;
case U8G_COM_MSG_WRITE_SEQ:
break;
}
return 1;
}

@ -0,0 +1,124 @@
/*
u8g_com_raspberrypi_hw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Assumes, that
MOSI is at PORTB, Pin 3
and
SCK is at PORTB, Pin 5
Update for ATOMIC operation done (01 Jun 2013)
U8G_ATOMIC_OR(ptr, val)
U8G_ATOMIC_AND(ptr, val)
U8G_ATOMIC_START()
U8G_ATOMIC_END()
*/
#include "u8g.h"
#if defined(U8G_RASPBERRY_PI)
#include <wiringPiSPI.h>
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
// check wiringPi setup
if (wiringPiSetup() == -1)
{
printf("wiringPi-Error\n");
exit(1);
}
if (wiringPiSPISetup (0, 100000) < 0)
{
printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ;
exit (1) ;
}
u8g_SetPIOutput(u8g, U8G_PI_RESET);
u8g_SetPIOutput(u8g, U8G_PI_A0);
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
/* Done by the SPI hardware */
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_WRITE_BYTE:
wiringPiSPIDataRW (0, &arg_val, 1) ;
break;
case U8G_COM_MSG_WRITE_SEQ:
wiringPiSPIDataRW (0, arg_ptr, arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ_P:
wiringPiSPIDataRW (0, arg_ptr, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,176 @@
/*
Special pin usage:
U8G_PI_I2C_OPTION additional options
U8G_PI_A0_STATE used to store the last value of the command/data register selection
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
U8G_PI_SCL clock line (NOT USED)
U8G_PI_SDA data line (NOT USED)
U8G_PI_RESET reset line (currently disabled, see below)
Protocol:
SLA, Cmd/Data Selection, Arguments
The command/data register is selected by a special instruction byte, which is sent after SLA
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
*/
#include "u8g.h"
#if defined(U8G_RASPBERRY_PI)
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define I2C_SLA 0x3c
#define I2C_CMD_MODE 0x000
#define I2C_DATA_MODE 0x040
#if defined(U8G_WITH_PINLIST)
uint8_t u8g_com_raspberrypi_ssd_start_sequence(u8g_t *u8g)
{
/* are we requested to set the a0 state? */
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
return 1;
/* setup bus, might be a repeated start */
if ( u8g_i2c_start(I2C_SLA) == 0 )
return 0;
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
{
if ( u8g_i2c_send_mode(I2C_CMD_MODE) == 0 )
return 0;
}
else
{
if ( u8g_i2c_send_mode(I2C_DATA_MODE) == 0 )
return 0;
}
u8g->pin_list[U8G_PI_SET_A0] = 0;
return 1;
}
uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
u8g_SetPIOutput(u8g, U8G_PI_RESET);
u8g_SetPIOutput(u8g, U8G_PI_A0);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
break;
case U8G_COM_MSG_CHIP_SELECT:
u8g->pin_list[U8G_PI_A0_STATE] = 0;
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
if ( arg_val == 0 )
{
/* disable chip, send stop condition */
u8g_i2c_stop();
}
else
{
/* enable, do nothing: any byte writing will trigger the i2c start */
}
break;
case U8G_COM_MSG_WRITE_BYTE:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
if ( u8g_i2c_send_byte(arg_val) == 0 )
return u8g_i2c_stop(), 0;
// u8g_i2c_stop();
break;
case U8G_COM_MSG_WRITE_SEQ:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
{
register uint8_t *ptr = (uint8_t *)arg_ptr;
while( arg_val > 0 )
{
if ( u8g_i2c_send_byte(*ptr++) == 0 )
return u8g_i2c_stop(), 0;
arg_val--;
}
}
// u8g_i2c_stop();
break;
case U8G_COM_MSG_WRITE_SEQ_P:
//u8g->pin_list[U8G_PI_SET_A0] = 1;
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
return u8g_i2c_stop(), 0;
{
register uint8_t *ptr = (uint8_t *)arg_ptr;
while( arg_val > 0 )
{
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
return 0;
ptr++;
arg_val--;
}
}
// u8g_i2c_stop();
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
#ifdef OLD_CODE
if ( i2c_state != 0 )
{
u8g_i2c_stop();
i2c_state = 0;
}
if ( u8g_com_raspberrypi_ssd_start_sequence(arg_val) == 0 )
return 0;
/* setup bus, might be a repeated start */
/*
if ( u8g_i2c_start(I2C_SLA) == 0 )
return 0;
if ( arg_val == 0 )
{
i2c_state = 1;
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
return 0;
}
else
{
i2c_state = 2;
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
return 0;
}
*/
#endif
break;
}
return 1;
}
#else /* defined(U8G_WITH_PINLIST) */
uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
return 1;
}
#endif /* defined(U8G_WITH_PINLIST) */
#endif

@ -0,0 +1,140 @@
/*
u8g_com_std_sw_spi.c
Universal 8bit Graphics Library
Copyright (c) 2015, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#if defined(U8G_WITH_PINLIST)
static void u8g_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val)
{
uint8_t i = 8;
do
{
if ( val & 128 )
u8g_SetPinLevel(dataPin, 1);
else
u8g_SetPinLevel(dataPin, 0);
val <<= 1;
u8g_MicroDelay(); /* 23 Sep 2012 */
//delay(1);
u8g_SetPinLevel(clockPin, 1);
u8g_MicroDelay(); /* 23 Sep 2012 */
//delay(1);
u8g_SetPinLevel(clockPin, 0);
u8g_MicroDelay(); /* 23 Sep 2012 */
//delay(1);
i--;
} while( i != 0 );
}
uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_INIT:
u8g_SetPIOutput(u8g, U8G_PI_SCK);
u8g_SetPIOutput(u8g, U8G_PI_MOSI);
u8g_SetPIOutput(u8g, U8G_PI_RESET);
u8g_SetPIOutput(u8g, U8G_PI_CS);
u8g_SetPIOutput(u8g, U8G_PI_A0);
u8g_SetPILevel(u8g, U8G_PI_SCK, 0);
u8g_SetPILevel(u8g, U8G_PI_MOSI, 0);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* disable */
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
}
else
{
/* enable */
u8g_SetPILevel(u8g, U8G_PI_SCK, 0);
u8g_SetPILevel(u8g, U8G_PI_CS, 0);
}
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P:
{
register uint8_t *ptr = arg_ptr;
while( arg_val > 0 )
{
u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
}
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
break;
}
return 1;
}
#else
uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
return 1;
}
#endif

@ -0,0 +1,99 @@
/*
u8g_cursor.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font)
{
u8g->cursor_font = cursor_font;
}
void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding)
{
u8g->cursor_encoding = encoding;
}
void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg)
{
u8g->cursor_bg_color = bg;
u8g->cursor_fg_color = fg;
}
void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y)
{
u8g->cursor_x = cursor_x;
u8g->cursor_y = cursor_y;
}
void u8g_EnableCursor(u8g_t *u8g)
{
u8g->cursor_fn = u8g_DrawCursor;
}
void u8g_DisableCursor(u8g_t *u8g)
{
u8g->cursor_fn = (u8g_draw_cursor_fn)0;
}
void u8g_DrawCursor(u8g_t *u8g)
{
const u8g_pgm_uint8_t *font;
uint8_t color;
uint8_t encoding = u8g->cursor_encoding;
/* get current values */
color = u8g_GetColorIndex(u8g);
font = u8g->font;
/* draw cursor */
u8g->font = u8g->cursor_font;
encoding++;
u8g_SetColorIndex(u8g, u8g->cursor_bg_color);
/* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */
/* required, because y adjustment should not happen to the cursor fonts */
u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding);
encoding--;
u8g_SetColorIndex(u8g, u8g->cursor_fg_color);
/* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */
/* required, because y adjustment should not happen to the cursor fonts */
/* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */
u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding);
/* restore previous values */
u8g->font = font;
u8g_SetColorIndex(u8g, color);
}

@ -0,0 +1,310 @@
/*
u8g_delay.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
void u8g_Delay(uint16_t val) Delay by "val" milliseconds
void u8g_MicroDelay(void) Delay be one microsecond
void u8g_10MicroDelay(void) Delay by 10 microseconds
*/
#include "u8g.h"
/*==== Part 1: Derive suitable delay procedure ====*/
#if defined(ARDUINO)
# if ARDUINO < 100
# include <WProgram.h>
# else
# include <Arduino.h>
# endif
# if defined(__AVR__)
# define USE_AVR_DELAY
# elif defined(__PIC32MX)
# define USE_PIC32_DELAY
# elif defined(__arm__) /* Arduino Due & Teensy */
# define USE_ARDUINO_DELAY
# else
# define USE_ARDUINO_DELAY
# endif
#elif defined(_GNU_SOURCE)
# define USE_LINUX_DELAY
#elif defined(__MSP430__)
# define USE_MSP430_DELAY
#elif defined(U8G_RASPBERRY_PI)
# define USE_RASPBERRYPI_DELAY
#elif defined(__AVR__)
# define USE_AVR_DELAY
#elif defined(__18CXX)
# define USE_PIC18_DELAY
#elif defined(__arm__)
/* do not define anything, all procedures are expected to be defined outside u8glib */
/*
void u8g_Delay(uint16_t val);
void u8g_MicroDelay(void);
void u8g_10MicroDelay(void);
*/
#else
# define USE_DUMMY_DELAY
#endif
/*==== Part 2: Definition of the delay procedures ====*/
/*== Raspberry Pi Delay ==*/
#if defined (USE_RASPBERRYPI_DELAY)
#include <wiringPi.h>
//#include "/usr/local/include/wiringPi.h"
void u8g_Delay(uint16_t val) {
//delay(val);
//usleep((uint32_t)val*(uint32_t)1000);
delayMicroseconds((uint32_t)val*(uint32_t)1000);
}
void u8g_MicroDelay(void)
{
usleep(1);
}
void u8g_10MicroDelay(void)
{
usleep(10);
}
#endif
#if defined(USE_LINUX_DELAY)
void u8g_Delay(uint16_t val) {
//delay(val);
usleep((uint32_t)val*(uint32_t)1000);
}
void u8g_MicroDelay(void)
{
usleep(1);
}
void u8g_10MicroDelay(void)
{
usleep(10);
}
#endif
/*== AVR Delay ==*/
#if defined(USE_AVR_DELAY)
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
/*
Delay by the provided number of milliseconds.
Thus, a 16 bit value will allow a delay of 0..65 seconds
Makes use of the _delay_loop_2
_delay_loop_2 will do a delay of n * 4 prozessor cycles.
with f = F_CPU cycles per second,
n = f / (1000 * 4 )
with f = 16000000 the result is 4000
with f = 1000000 the result is 250
the millisec loop, gcc requires the following overhead:
- movev 1
- subwi 2x2
- bne i 2
==> 7 cycles
==> must be devided by 4, rounded up 7/4 = 2
*/
void u8g_Delay(uint16_t val)
{
/* old version did a call to the arduino lib: delay(val); */
while( val != 0 )
{
_delay_loop_2( (F_CPU / 4000 ) -2);
val--;
}
}
/* delay by one micro second */
void u8g_MicroDelay(void)
{
#if (F_CPU / 4000000 ) > 0
_delay_loop_2( (F_CPU / 4000000 ) );
#endif
}
/* delay by 10 micro seconds */
void u8g_10MicroDelay(void)
{
#if (F_CPU / 400000 ) > 0
_delay_loop_2( (F_CPU / 400000 ) );
#endif
}
#endif
/*== Delay for PIC18 (not tested) ==*/
#if defined(USE_PIC18_DELAY)
#include <delays.h>
#define GetSystemClock() (64000000ul) // Hz
#define GetInstructionClock() (GetSystemClock()/4)
void u8g_Delay(uint16_t val)
{/*
unsigned int _iTemp = (val);
while(_iTemp--)
Delay1KTCYx((GetInstructionClock()+999999)/1000000);
*/
}
void u8g_MicroDelay(void)
{
/* not implemented */
}
void u8g_10MicroDelay(void)
{
/* not implemented */
}
#endif
/*== Arduino Delay ==*/
#if defined(USE_ARDUINO_DELAY)
void u8g_Delay(uint16_t val)
{
#if defined(__arm__)
delayMicroseconds((uint32_t)val*(uint32_t)1000);
#else
delay(val);
#endif
}
void u8g_MicroDelay(void)
{
delayMicroseconds(1);
}
void u8g_10MicroDelay(void)
{
delayMicroseconds(10);
}
#endif
#if defined(USE_PIC32_DELAY)
/*
Assume chipkit here with F_CPU correctly defined
The problem was, that u8g_Delay() is called within the constructor.
It seems that the chipkit is not fully setup at this time, so a
call to delay() will not work. So here is my own implementation.
*/
#define CPU_COUNTS_PER_SECOND (F_CPU/2UL)
#define TICKS_PER_MILLISECOND (CPU_COUNTS_PER_SECOND/1000UL)
#include "plib.h"
void u8g_Delay(uint16_t val)
{
uint32_t d;
uint32_t s;
d = val;
d *= TICKS_PER_MILLISECOND;
s = ReadCoreTimer();
while ( (uint32_t)(ReadCoreTimer() - s) < d )
;
}
void u8g_MicroDelay(void)
{
uint32_t d;
uint32_t s;
d = TICKS_PER_MILLISECOND/1000;
s = ReadCoreTimer();
while ( (uint32_t)(ReadCoreTimer() - s) < d )
;
}
void u8g_10MicroDelay(void)
{
uint32_t d;
uint32_t s;
d = TICKS_PER_MILLISECOND/100;
s = ReadCoreTimer();
while ( (uint32_t)(ReadCoreTimer() - s) < d )
;
}
#endif
#if defined(USE_MSP430_DELAY)
#include <msp430.h>
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
void u8g_Delay(uint16_t val)
{
int t;
for (t=0; t < val; t++)
{
__delay_cycles(F_CPU/1000UL);
}
}
void u8g_MicroDelay(void)
{
__delay_cycles(F_CPU/1000000UL);
}
void u8g_10MicroDelay(void)
{
__delay_cycles(F_CPU/100000UL);
}
#endif
/*== Any other systems: Dummy Delay ==*/
#if defined(USE_DUMMY_DELAY)
void u8g_Delay(uint16_t val)
{
/* do not know how to delay... */
}
void u8g_MicroDelay(void)
{
}
void u8g_10MicroDelay(void)
{
}
#endif

@ -0,0 +1,199 @@
/*
u8g_dev_a2_micro_printer_ds.c
Use DC2 bitmap command of the A2 Micro panel termal printer
double stroke
Universal 8bit Graphics Library
Copyright (c) 2013, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define LINE_DELAY 40
uint8_t u8g_dev_a2_micro_printer_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i, j;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
y = pb->p.page_y0;
ptr = pb->buf;
u8g_WriteByte(u8g, dev, 27); /* ESC */
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
u8g_WriteByte(u8g, dev, 18); /* DC2 */
u8g_WriteByte(u8g, dev, 42 ); /* * */
u8g_WriteByte(u8g, dev, pb->p.page_height );
u8g_WriteByte(u8g, dev, pb->width/8 );
for( i = 0; i < pb->p.page_height; i ++ )
{
for( j = 0; j < pb->width/8; j++ )
{
u8g_WriteByte(u8g, dev, *ptr);
ptr++;
}
u8g_Delay(LINE_DELAY);
y++;
}
/* set parameters back to their default values */
u8g_WriteByte(u8g, dev, 27); /* ESC */
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
}
break;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
static uint8_t u8g_dev_expand4(uint8_t val)
{
uint8_t a,b,c,d;
a = val&1;
b = (val&2)<<1;
c = (val&4)<<2;
d = (val&8)<<3;
a |=b;
a |=c;
a |=d;
a |= a<<1;
return a;
}
uint8_t u8g_dev_a2_micro_printer_double_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
{
//u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
//u8g_WriteByte(u8g, dev, 18); /* DC2 */
//u8g_WriteByte(u8g, dev, 42 ); /* * */
//u8g_WriteByte(u8g, dev, pb->p.total_height*2 );
//u8g_WriteByte(u8g, dev, pb->width/8*2 );
}
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i, j;
uint8_t *ptr;
uint8_t *p2;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
y = pb->p.page_y0;
ptr = pb->buf;
//u8g_WriteByte(u8g, dev, 18); /* DC2 */
//u8g_WriteByte(u8g, dev, 35 ); /* # */
//u8g_WriteByte(u8g, dev, 0x0ff ); /* max */
u8g_WriteByte(u8g, dev, 27); /* ESC */
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
u8g_WriteByte(u8g, dev, 18); /* DC2 */
u8g_WriteByte(u8g, dev, 42 ); /* * */
u8g_WriteByte(u8g, dev, pb->p.page_height*2 );
u8g_WriteByte(u8g, dev, pb->width/8*2 );
for( i = 0; i < pb->p.page_height; i ++ )
{
p2 = ptr;
for( j = 0; j < pb->width/8; j++ )
{
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
p2++;
}
u8g_Delay(LINE_DELAY);
p2 = ptr;
for( j = 0; j < pb->width/8; j++ )
{
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
p2++;
}
u8g_Delay(LINE_DELAY);
ptr += pb->width/8;
y++;
}
/* set parameters back to their default values */
u8g_WriteByte(u8g, dev, 27); /* ESC */
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
}
break;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
#if defined(U8G_16BIT)
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 384, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 360, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 720, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
#else
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 240, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
#endif
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x120_ds, 192, 120, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);

@ -0,0 +1,92 @@
/*
u8g_dev_flipdisc.c
1-Bit (BW) Driver for flip disc matrix
2x 7 pixel height
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 28
#define HEIGHT 14
#define PAGE_HEIGHT 14
/*
Write data to the flip disc matrix.
This procedure must be implemented by the user.
Arguments:
id: Id for the matrix. Currently always 0.
page: A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0
width: The width of the flip disc matrix. Always equal to WIDTH
row1: first data line (7 pixel per byte)
row2: first data line (7 pixel per byte)
*/
void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2);
void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2);
void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2))
{
u8g_write_flip_disc_matrix = cb;
}
uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
/* current page: pb->p.page */
/* ptr to the buffer: pb->buf */
(*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH);
}
break;
case U8G_DEV_MSG_CONTRAST:
return 1;
}
return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf};
u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn };

@ -0,0 +1,130 @@
/*
u8g_dev_gprof.c
Device for performance measurement with gprof.
Does not write any data, but uses a buffer.
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
uint8_t u8g_pb_dev_gprof_buf[WIDTH];
u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf };
u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL };
uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
/*
{
uint8_t i, j;
uint8_t page_height;
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( j = 0; j < page_height; j++ )
{
printf("%02d ", j);
for( i = 0; i < WIDTH; i++ )
{
if ( (u8g_pb_dev_stdout_buf[i] & (1<<j)) != 0 )
printf("#");
else
printf(".");
}
printf("\n");
}
}
*/
if ( u8g_page_Next(&(pb->p)) == 0 )
{
//printf("\n");
return 0;
}
u8g_pb_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
{
u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
u8g_uint_t x2, y2;
y2 = bbx->y;
y2 += bbx->h;
y2--;
if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 )
return 0;
/* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */
x2 = bbx->x;
x2 += bbx->w;
x2--;
if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 )
return 0;
}
return 1;
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}

@ -0,0 +1,281 @@
/*
u8g_dev_ht1632.c
1-Bit (BW) Driver for HT1632 controller
Universal 8bit Graphics Library
Copyright (c) 2013, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
U8G_PIN_NONE can be used as argument
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
{
...
u8g->pin_list[U8G_PI_SCK] = sck;
u8g->pin_list[U8G_PI_MOSI] = mosi;
u8g->pin_list[U8G_PI_CS] = cs;
u8g->pin_list[U8G_PI_A0] = a0;
u8g->pin_list[U8G_PI_RESET] = reset;
mapping
#define DATA_PIN --> U8G_PI_MOSI
#define WR_PIN --> U8G_PI_SCK
#define CS_PIN --> U8G_PI_CS
U8G_PI_A0 --> not used
U8G_PI_RESET --> not used
Usage:
u8g_InitSPI(&u8g, &u8g_dev_ht1632_24x16, WR_PIN, DATA_IN, CS_PIN, U8G_PIN_NONE, U8G_PIN_NONE)
*/
#include "u8g.h"
#define WIDTH 24
#define HEIGHT 16
#define PAGE_HEIGHT 16
/* http://forum.arduino.cc/index.php?topic=168537.0 */
#define HT1632_CMD_SYSDIS 0x00 // CMD= 0000-0000-x Turn off oscil
#define HT1632_CMD_SYSON 0x01 // CMD= 0000-0001-x Enable system oscil
#define HT1632_CMD_LEDOFF 0x02 // CMD= 0000-0010-x LED duty cycle gen off
#define HT1632_CMD_LEDON 0x03 // CMD= 0000-0011-x LEDs ON
#define HT1632_CMD_BLOFF 0x08 // CMD= 0000-1000-x Blink OFF
#define HT1632_CMD_BLON 0x09 // CMD= 0000-1001-x Blink On
#define HT1632_CMD_SLVMD 0x10 // CMD= 0001-00xx-x Slave Mode
#define HT1632_CMD_MSTMD 0x14 // CMD= 0001-01xx-x Master Mode
#define HT1632_CMD_RCCLK 0x18 // CMD= 0001-10xx-x Use on-chip clock
#define HT1632_CMD_EXTCLK 0x1C // CMD= 0001-11xx-x Use external clock
#define HT1632_CMD_COMS00 0x20 // CMD= 0010-ABxx-x commons options
#define HT1632_CMD_COMS01 0x24 // CMD= 0010-ABxx-x commons options
#define HT1632_CMD_COMS10 0x28 // CMD= 0010-ABxx-x commons options
#define HT1632_CMD_COMS11 0x2C // P-MOS OUTPUT AND 16COMMON OPTION
#define HT1632_CMD_PWM 0xA0 // CMD= 101x-PPPP-x PWM duty cycle
#define HT1632_ID_CMD 4 /* ID = 100 - Commands */
#define HT1632_ID_RD 6 /* ID = 110 - Read RAM */
#define HT1632_ID_WR 5 /* ID = 101 - Write RAM */
#define HT1632_ID_LEN 3 // IDs are 3 bits
#define HT1632_CMD_LEN 8 // CMDs are 8 bits
#define HT1632_DATA_LEN 8 // Data are 4*2 bits
#define HT1632_ADDR_LEN 7 // Address are 7 bits
#if defined(ARDUINO)
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
//#define WR_PIN 3
//#define DATA_PIN 2
//#define CS_PIN 4
void ht1632_write_data_MSB(u8g_t *u8g, uint8_t cnt, uint8_t data, uint8_t extra)
{
int8_t i;
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
for(i = cnt - 1; i >= 0; i--)
{
if ((data >> i) & 1)
{
digitalWrite(data_pin, HIGH);
}
else
{
digitalWrite(data_pin, LOW);
}
digitalWrite(wr_pin, LOW);
u8g_MicroDelay();
digitalWrite(wr_pin, HIGH);
u8g_MicroDelay();
}
// Send an extra bit
if (extra)
{
digitalWrite(data_pin, HIGH);
digitalWrite(wr_pin, LOW);
u8g_MicroDelay();
digitalWrite(wr_pin, HIGH);
u8g_MicroDelay();
}
}
void ht1632_write_data(u8g_t *u8g, uint8_t cnt, uint8_t data)
{
uint8_t i;
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
for (i = 0; i < cnt; i++)
{
if ((data >> i) & 1) {
digitalWrite(data_pin, HIGH);
}
else {
digitalWrite(data_pin, LOW);
}
digitalWrite(wr_pin, LOW);
u8g_MicroDelay();
digitalWrite(wr_pin, HIGH);
u8g_MicroDelay();
}
}
void ht1632_init(u8g_t *u8g)
{
//uint8_t i;
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
pinMode(data_pin, OUTPUT);
pinMode(wr_pin, OUTPUT);
pinMode(cs_pin, OUTPUT);
digitalWrite(data_pin, HIGH);
digitalWrite(wr_pin, HIGH);
digitalWrite(cs_pin, HIGH);
digitalWrite(cs_pin, LOW);
/* init display once after startup */
ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false); // IDs are 3 bits
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSDIS, true); // 8 bits
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSON, true); // 8 bits
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_COMS11, true); // 8 bits
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_LEDON, true); // 8 bits
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_BLOFF, true); // 8 bits
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM+15, true); // 8 bits
digitalWrite(cs_pin, HIGH);
/* removed following (debug) code */
/*
digitalWrite(cs_pin, LOW);
ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
ht1632_write_data_MSB(u8g, 7, 0, false);
for(i = 0; i<48; ++i)
{
ht1632_write_data(u8g, 8, 0xFF);
}
digitalWrite(cs_pin, HIGH);
*/
}
/*
page: 0=data contain lines 0..16, 1=data contain lines 16..32 (a 24x16 display will only have page 0)
cnt: width of the display
data: pointer to a buffer with 2*cnt bytes.
*/
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
{
uint8_t addr;
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
/* send data to the ht1632 */
digitalWrite(cs_pin, LOW);
ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
ht1632_write_data_MSB(u8g, 7, page*2*cnt, false);
// Operating in progressive addressing mode
for (addr = 0; addr < cnt; addr++)
{
ht1632_write_data(u8g, 8, data[addr]);
ht1632_write_data(u8g, 8, data[addr+cnt]);
}
digitalWrite(cs_pin, HIGH);
}
/* value is between 0...15 */
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
{
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
digitalWrite(cs_pin, LOW);
ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false);
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM + value, false);
digitalWrite(cs_pin, HIGH);
}
#else
void ht1632_init(u8g_t *u8g)
{
}
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
{
}
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
{
}
#endif /* ARDUINO */
uint8_t u8g_dev_ht1632_24x16_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
ht1632_init(u8g);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
/* current page: pb->p.page */
/* ptr to the buffer: pb->buf */
ht1632_transfer_data(u8g, pb->p.page, WIDTH, pb->buf);
}
break;
case U8G_DEV_MSG_CONTRAST:
/* values passed to SetContrast() are between 0 and 255, scale down to 0...15 */
ht1632_set_contrast(u8g, (*(uint8_t *)arg) >> 4);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ht1632_24x16_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ht1632_24x16_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ht1632_24x16_buf};
u8g_dev_t u8g_dev_ht1632_24x16 = { u8g_dev_ht1632_24x16_fn, &u8g_dev_ht1632_24x16_pb, u8g_com_null_fn };

@ -0,0 +1,326 @@
/*
u8g_dev_ili9325d_320x240.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Color format
Red: 5 Bit
Green: 6 Bit
Blue: 5 Bit
*/
#include "u8g.h"
#define WIDTH 240
#if defined(U8G_16BIT)
#define HEIGHT 320
#else
/* if the user tries to compile the 8Bit version of the lib, then restrict the height to something which fits to 8Bit */
#define HEIGHT 240
#endif
#define PAGE_HEIGHT 4
/*
reference board for this device:
http://iteadstudio.com/store/index.php?main_page=product_info&cPath=57_58&products_id=55
documentation:
http://iteadstudio.com/Downloadfile/ITDB02_material.rar
datasheet
http://www.newhavendisplay.com/app_notes/ILI9325D.pdf
other libs
http://henningkarlsen.com/electronics/library.php
init sequence
http://code.google.com/p/itdb02/, ITDB02.cpp, iteadstudio.com
*/
static const uint8_t u8g_dev_ili9325d_320x240_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
//U8G_ESC_ADR(0), 0x000, 0x0E5, /* only used for none D version: set SRAM internal timing */
//U8G_ESC_ADR(1), 0x078, 0x0f0,
U8G_ESC_ADR(0), 0x000, 0x001, /* Driver Output Control, bits 8 & 10 */
U8G_ESC_ADR(1), 0x001, 0x000,
U8G_ESC_ADR(0), 0x000, 0x002, /* LCD Driving Wave Control, bit 9: Set line inversion */
U8G_ESC_ADR(1), 0x002, 0x000, /* ITDB02 none D verion: 0x007, 0x000 */
U8G_ESC_ADR(0), 0x000, 0x003, /* Entry Mode, GRAM write direction and BGR=1 */
U8G_ESC_ADR(1), 0x010, 0x030,
U8G_ESC_ADR(0), 0x000, 0x004, /* Resize register */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x008, /* Display Control 2: set the back porch and front porch */
U8G_ESC_ADR(1), 0x002, 0x007,
U8G_ESC_ADR(0), 0x000, 0x009, /* Display Control 3 */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x00a, /* Display Control 4: FMARK */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x00c, /* RGB Display Interface Control 1 */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x00d, /* Frame Maker Position */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x00f, /* RGB Display Interface Control 2 */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x010, /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x011, /* Power Control 2: DC1[2:0], DC0[2:0], VC[2:0] */
U8G_ESC_ADR(1), 0x000, 0x007,
U8G_ESC_ADR(0), 0x000, 0x012, /* Power Control 3: VREG1OUT voltage */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x013, /* Power Control 4: VDV[4:0] for VCOM amplitude */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x007, /* Display Control 1: Operate, but do not display */
U8G_ESC_ADR(1), 0x000, 0x001,
U8G_ESC_DLY(100), /* delay 100 ms */ /* ITDB02 none D verion: 50ms */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_ADR(0), 0x000, 0x010, /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
U8G_ESC_ADR(1), 0x016, 0x090, /* ITDB02 none D verion: 0x010, 0x090 */
U8G_ESC_ADR(0), 0x000, 0x011, /* Power Control 2: SAP, BT[3:0], AP, DSTB, SLP, STB */
U8G_ESC_ADR(1), 0x002, 0x027,
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(0), 0x000, 0x012, /* Power Control 3: VCI: External, VCI*1.80 */
U8G_ESC_ADR(1), 0x000, 0x00d, /* ITDB02 none D verion: 0x000, 0x01f */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(0), 0x000, 0x013, /* Power Control 4: VDV[4:0] for VCOM amplitude */
U8G_ESC_ADR(1), 0x012, 0x000, /* ITDB02 none D verion: 0x015, 0x000 */
U8G_ESC_ADR(0), 0x000, 0x029, /* Power Control 7 */
U8G_ESC_ADR(1), 0x000, 0x00a, /* ITDB02 none D verion: 0x000, 0x027 */
U8G_ESC_ADR(0), 0x000, 0x02b, /* Frame Rate: 83 */
U8G_ESC_ADR(1), 0x000, 0x00d,
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(0), 0x000, 0x020, /* Horizontal GRAM Address Set */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x021, /* Vertical GRAM Address Set */
U8G_ESC_ADR(1), 0x000, 0x000,
/* gamma control */
U8G_ESC_ADR(0), 0x000, 0x030,
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x031,
U8G_ESC_ADR(1), 0x004, 0x004,
U8G_ESC_ADR(0), 0x000, 0x032,
U8G_ESC_ADR(1), 0x000, 0x003,
U8G_ESC_ADR(0), 0x000, 0x035,
U8G_ESC_ADR(1), 0x004, 0x005,
U8G_ESC_ADR(0), 0x000, 0x036,
U8G_ESC_ADR(1), 0x008, 0x008,
U8G_ESC_ADR(0), 0x000, 0x037,
U8G_ESC_ADR(1), 0x004, 0x007,
U8G_ESC_ADR(0), 0x000, 0x038,
U8G_ESC_ADR(1), 0x003, 0x003,
U8G_ESC_ADR(0), 0x000, 0x039,
U8G_ESC_ADR(1), 0x007, 0x007,
U8G_ESC_ADR(0), 0x000, 0x03c,
U8G_ESC_ADR(1), 0x005, 0x004,
U8G_ESC_ADR(0), 0x000, 0x03d,
U8G_ESC_ADR(1), 0x008, 0x008,
U8G_ESC_ADR(0), 0x000, 0x050, /* Horizontal GRAM Start Address */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x051, /* Horizontal GRAM End Address: 239 */
U8G_ESC_ADR(1), 0x000, 0x0EF,
U8G_ESC_ADR(0), 0x000, 0x052, /* Vertical GRAM Start Address */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x053, /* Vertical GRAM End Address: 319 */
U8G_ESC_ADR(1), 0x001, 0x03F,
U8G_ESC_ADR(0), 0x000, 0x060, /* Driver Output Control 2 */
U8G_ESC_ADR(1), 0x0a7, 0x000,
U8G_ESC_ADR(0), 0x000, 0x061, /* Base Image Display Control: NDL,VLE, REV */
U8G_ESC_ADR(1), 0x000, 0x001,
U8G_ESC_ADR(0), 0x000, 0x06a, /* Vertical Scroll Control */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x080, /* Partial Image 1 Display Position */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x081, /* Partial Image 1 RAM Start Address */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x082, /* Partial Image 1 RAM End Address */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x083, /* Partial Image 2 Display Position */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x084, /* Partial Image 2 RAM Start Address */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x085, /* Partial Image 2 RAM End Address */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x090, /* Panel Interface Control 1 */
U8G_ESC_ADR(1), 0x000, 0x010,
U8G_ESC_ADR(0), 0x000, 0x092, /* Panel Interface Control 2 */
U8G_ESC_ADR(1), 0x000, 0x000, /* 0x006, 0x000 */
U8G_ESC_ADR(0), 0x000, 0x007, /* Display Control 1: Operate, display ON */
U8G_ESC_ADR(1), 0x001, 0x033,
U8G_ESC_DLY(10), /* delay 10 ms */
/* write test pattern */
U8G_ESC_ADR(0), 0x000, 0x020, /* Horizontal GRAM Address Set */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x021, /* Vertical GRAM Address Set */
U8G_ESC_ADR(1), 0x000, 0x010,
U8G_ESC_ADR(0), 0x000, 0x022, /* Write Data to GRAM */
U8G_ESC_ADR(1), 0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
0x000, 0x000,
0x0fe, 0x0fe,
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ili9325d_320x240_page_seq[] PROGMEM = {
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_ADR(0), 0x000, 0x020, /* Horizontal GRAM Address Set */
U8G_ESC_ADR(1), 0x000, 0x000,
U8G_ESC_ADR(0), 0x000, 0x021, /* Vertical GRAM Address Set */
U8G_ESC_ADR(1),
U8G_ESC_END /* end of sequence */
};
/* convert the internal RGB 332 to 65K high byte */
static uint8_t u8g_dev_ili9325d_get_65K_high_byte(uint8_t color)
{
uint8_t h;
h = color;
h &= 0x0e0;
h |= h>>3;
h &= 0x0f8;
color>>=2;
color &= 7;
h |= color;
return h;
}
/* convert the internal RGB 332 to 65K high byte */
static uint8_t u8g_dev_ili9325d_get_65K_low_byte(uint8_t color)
{
uint8_t l;
l = color;
l <<= 3;
color &= 3;
color <<= 1;
l |= color;
return l;
}
uint8_t u8g_dev_ili9325d_320x240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
//for(;;)
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ili9325d_320x240_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
uint16_t y, j;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < pb->p.page_height; i ++ )
{
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ili9325d_320x240_page_seq);
u8g_WriteByte(u8g, dev, y >> 8 ); /* display ram (cursor) address high byte */
u8g_WriteByte(u8g, dev, y & 255 ); /* display ram (cursor) address low byte */
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0 );
u8g_WriteByte(u8g, dev, 0x022 ); /* start gram data */
u8g_SetAddress(u8g, dev, 1); /* data mode */
for( j = 0; j < pb->width; j++ )
{
u8g_WriteByte(u8g, dev, u8g_dev_ili9325d_get_65K_high_byte(*ptr) );
u8g_WriteByte(u8g, dev, u8g_dev_ili9325d_get_65K_low_byte(*ptr) );
ptr++;
}
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_ili9325d_320x240_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
u8g_pb_t u8g_ili9325d_320x240_8h8_pb U8G_NOCOMMON = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_ili9325d_320x240_8h8_buf};
u8g_dev_t u8g_dev_ili9325d_320x240_8bit U8G_NOCOMMON = { u8g_dev_ili9325d_320x240_fn, &u8g_ili9325d_320x240_8h8_pb, u8g_com_arduino_port_d_wr_fn };
//u8g_dev_t u8g_dev_ili9325d_320x240_8bit = { u8g_dev_ili9325d_320x240_fn, &u8g_ili9325d_320x240_8h8_pb, u8g_com_arduino_parallel_fn };
//U8G_PB_DEV(u8g_dev_ili9325d_320x240_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ili9325d_320x240_fn, U8G_COM_PARALLEL);

@ -0,0 +1,110 @@
/*
u8g_dev_ks0108_128x64.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ADDRESS = 0 (Command Mode)
0x03f Display On
0x0c0 Start Display at line 0
0x040 | y write to y address (y:0..63)
0x0b8 | x write to page [0..7]
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_ks0108_128x64_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip 1 */
0x03f, /* display on */
0x0c0, /* start at line 0 */
U8G_ESC_DLY(20), /* delay 20 ms */
U8G_ESC_CS(2), /* enable chip 2 */
0x03f, /* display on */
0x0c0, /* start at line 0 */
U8G_ESC_DLY(20), /* delay 20 ms */
U8G_ESC_CS(0), /* disable all chips */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* command mode */
u8g_SetChipSelect(u8g, dev, 2);
u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */
u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, 64, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_SetAddress(u8g, dev, 0); /* command mode */
u8g_SetChipSelect(u8g, dev, 1);
u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */
u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, 64, 64+(uint8_t *)pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ks0108_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_PARALLEL);
U8G_PB_DEV(u8g_dev_ks0108_128x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_FAST_PARALLEL);

@ -0,0 +1,147 @@
/*
u8g_dev_lc7981_160x80.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 160
#define HEIGHT 80
#define PAGE_HEIGHT 8
/*
code ideas:
https://github.com/vsergeev/embedded-drivers/tree/master/avr-lc7981
data sheets:
http://www.lcd-module.de/eng/pdf/zubehoer/lc7981.pdf
http://www.lcd-module.de/pdf/grafik/w160-6.pdf
*/
static const uint8_t u8g_dev_lc7981_160x80_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(1), /* instruction mode */
0x000, /* mode register */
U8G_ESC_ADR(0), /* data mode */
0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
U8G_ESC_ADR(1), /* instruction mode */
0x001, /* character/bits per pixel pitch */
U8G_ESC_ADR(0), /* data mode */
0x007, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x002, /* number of chars/byte width of the screen */
U8G_ESC_ADR(0), /* data mode */
WIDTH/8-1, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x003, /* time division */
U8G_ESC_ADR(0), /* data mode */
0x07f, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x008, /* display start low */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x009, /* display start high */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_lc7981_160x80_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_160x80_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint16_t disp_ram_adr;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
disp_ram_adr = WIDTH/8;
disp_ram_adr *= y;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00c ); /* write data */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
disp_ram_adr += WIDTH/8;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_lc7981_160x80_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_160x80_fn, U8G_COM_FAST_PARALLEL);

@ -0,0 +1,145 @@
/*
u8g_dev_lc7981_240x128.c
Hitachi Display SP14N002
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 240
#define HEIGHT 128
#define PAGE_HEIGHT 8
/*
http://www.mark-products.com/graphics.htm#240x128%20Pixel%20Format
*/
static const uint8_t u8g_dev_lc7981_240x128_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(1), /* instruction mode */
0x000, /* mode register */
U8G_ESC_ADR(0), /* data mode */
0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
U8G_ESC_ADR(1), /* instruction mode */
0x001, /* character/bits per pixel pitch */
U8G_ESC_ADR(0), /* data mode */
0x007, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x002, /* number of chars/byte width of the screen */
U8G_ESC_ADR(0), /* data mode */
WIDTH/8-1, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x003, /* time division */
U8G_ESC_ADR(0), /* data mode */
0x07f, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x008, /* display start low */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x009, /* display start high */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_lc7981_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint16_t disp_ram_adr;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
disp_ram_adr = WIDTH/8;
disp_ram_adr *= y;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00c ); /* write data */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
disp_ram_adr += WIDTH/8;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_lc7981_240x128_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x128_fn, U8G_COM_FAST_PARALLEL);

@ -0,0 +1,145 @@
/*
u8g_dev_lc7981_240x64.c
Tested with Nan Ya LM_J6_003_
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 240
#define HEIGHT 64
#define PAGE_HEIGHT 8
/*
http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format
*/
static const uint8_t u8g_dev_lc7981_240x64_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(1), /* instruction mode */
0x000, /* mode register */
U8G_ESC_ADR(0), /* data mode */
0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
U8G_ESC_ADR(1), /* instruction mode */
0x001, /* character/bits per pixel pitch */
U8G_ESC_ADR(0), /* data mode */
0x007, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x002, /* number of chars/byte width of the screen */
U8G_ESC_ADR(0), /* data mode */
WIDTH/8-1, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x003, /* time division */
U8G_ESC_ADR(0), /* data mode */
0x07f, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x008, /* display start low */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x009, /* display start high */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_lc7981_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint16_t disp_ram_adr;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
disp_ram_adr = WIDTH/8;
disp_ram_adr *= y;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00c ); /* write data */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
disp_ram_adr += WIDTH/8;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_lc7981_240x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x64_fn, U8G_COM_FAST_PARALLEL);

@ -0,0 +1,151 @@
/*
u8g_dev_lc7981_320x64.c
Note: Requires 16 bit mode (Must be enabled in u8g.h)
Tested with Varitronix MGLS32064-03.pdf
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#ifdef U8G_16BIT
#define WIDTH 320
#else
#define WIDTH 240
#endif
#define HEIGHT 64
#define PAGE_HEIGHT 8
/*
http://www.gaw.ru/pdf/lcd/lcm/Varitronix/graf/MGLS32064-03.pdf
*/
static const uint8_t u8g_dev_lc7981_320x64_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_ADR(1), /* instruction mode */
0x000, /* mode register */
U8G_ESC_ADR(0), /* data mode */
0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
U8G_ESC_ADR(1), /* instruction mode */
0x001, /* character/bits per pixel pitch */
U8G_ESC_ADR(0), /* data mode */
0x007, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x002, /* number of chars/byte width of the screen */
U8G_ESC_ADR(0), /* data mode */
WIDTH/8-1, /* 8 bits per pixel */
U8G_ESC_ADR(1), /* instruction mode */
0x003, /* time division */
U8G_ESC_ADR(0), /* data mode */
0x07f, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x008, /* display start low */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_ADR(1), /* instruction mode */
0x009, /* display start high */
U8G_ESC_ADR(0), /* data mode */
0x000, /* */
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_lc7981_320x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_320x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint16_t disp_ram_adr;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
disp_ram_adr = WIDTH/8;
disp_ram_adr *= y;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x00c ); /* write data */
u8g_SetAddress(u8g, dev, 0); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
disp_ram_adr += WIDTH/8;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_lc7981_320x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_320x64_fn, U8G_COM_FAST_PARALLEL);

@ -0,0 +1,232 @@
/*
u8g_dev_ld7032_60x32.c
60x32 OLED display
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
/* define width as 64, so that it is a multiple of 8 */
#define WIDTH 64
#define HEIGHT 32
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_ld7032_60x32_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_DLY(1), /* delay 1 ms */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_ADR(0), /* instruction mode */
0x002, /* Dot Matrix Display ON/OFF */
U8G_ESC_ADR(1), /* data mode */
0x001, /* ON */
U8G_ESC_ADR(0), /* instruction mode */
0x014, /* Dot Matrix Display Stand-by ON/OFF */
U8G_ESC_ADR(1), /* data mode */
0x000, /* ON */
U8G_ESC_ADR(0), /* instruction mode */
0x01a, /* Dot Matrix Frame Rate */
U8G_ESC_ADR(1), /* data mode */
0x004, /* special value for this OLED from manual */
U8G_ESC_ADR(0), /* instruction mode */
0x01d, /* Graphics Memory Writing Direction */
U8G_ESC_ADR(1), /* data mode */
0x000, /* reset default (right down, horizontal) */
U8G_ESC_ADR(0), /* instruction mode */
0x009, /* Display Direction */
U8G_ESC_ADR(1), /* data mode */
0x000, /* reset default (x,y: min --> max) */
U8G_ESC_ADR(0), /* instruction mode */
0x030, /* Display Size X */
U8G_ESC_ADR(1), /* data mode */
0x000, /* Column Start Output */
0x03b, /* Column End Output */
U8G_ESC_ADR(0), /* instruction mode */
0x032, /* Display Size Y */
U8G_ESC_ADR(1), /* data mode */
0x000, /* Row Start Output */
0x01f, /* Row End Output */
U8G_ESC_ADR(0), /* instruction mode */
0x010, /* Peak Pulse Width Set */
U8G_ESC_ADR(1), /* data mode */
0x000, /* 0 SCLK */
U8G_ESC_ADR(0), /* instruction mode */
0x016, /* Peak Pulse Delay Set */
U8G_ESC_ADR(1), /* data mode */
0x000, /* 0 SCLK */
U8G_ESC_ADR(0), /* instruction mode */
0x012, /* Dot Matrix Current Level Set */
U8G_ESC_ADR(1), /* data mode */
0x050, /* 0x050 * 1 uA = 80 uA */
U8G_ESC_ADR(0), /* instruction mode */
0x018, /* Pre-Charge Pulse Width */
U8G_ESC_ADR(1), /* data mode */
0x003, /* 3 SCLK */
U8G_ESC_ADR(0), /* instruction mode */
0x044, /* Pre-Charge Mode */
U8G_ESC_ADR(1), /* data mode */
0x002, /* Every Time */
U8G_ESC_ADR(0), /* instruction mode */
0x048, /* Row overlap timing */
U8G_ESC_ADR(1), /* data mode */
0x003, /* Pre-Charge + Peak Delay + Peak boot Timing */
U8G_ESC_ADR(0), /* instruction mode */
0x03f, /* VCC_R_SEL */
U8G_ESC_ADR(1), /* data mode */
0x011, /* ??? */
U8G_ESC_ADR(0), /* instruction mode */
0x03d, /* VSS selection */
U8G_ESC_ADR(1), /* data mode */
0x000, /* 2.8V */
U8G_ESC_ADR(0), /* instruction mode */
0x002, /* Dot Matrix Display ON/OFF */
U8G_ESC_ADR(1), /* data mode */
0x001, /* ON */
U8G_ESC_ADR(0), /* instruction mode */
0x008, /* write data */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* use box commands to set start adr */
static const uint8_t u8g_dev_ld7032_60x32_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_ADR(0), /* instruction mode */
0x034, /* box x start */
U8G_ESC_ADR(1), /* data mode */
0x000, /* 0 */
U8G_ESC_ADR(0), /* instruction mode */
0x035, /* box x end */
U8G_ESC_ADR(1), /* data mode */
0x007, /* */
U8G_ESC_ADR(0), /* instruction mode */
0x037, /* box y end */
U8G_ESC_ADR(1), /* data mode */
0x01f, /* */
U8G_ESC_ADR(0), /* instruction mode */
0x036, /* box y start */
U8G_ESC_ADR(1), /* data mode */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ld7032_60x32_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
/* ... */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ld7032_60x32_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
/* ... */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ld7032_60x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_data_start);
u8g_WriteByte(u8g, dev, pb->p.page_y0); /* y start */
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x008);
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_off);
return 1;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ld7032_60x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ld7032_60x32_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_PARALLEL);
U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_usart_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_USART_SPI);

@ -0,0 +1,67 @@
/*
u8g_dev_null.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL: /* most often used command */
break;
case U8G_DEV_MSG_SET_PIXEL:
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
break;
case U8G_DEV_MSG_PAGE_NEXT:
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return 1;
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
}
return 1;
}

@ -0,0 +1,141 @@
/*
u8g_dev_pcd8544_84x48.c
Display: Nokia 84x48
Status: Tested with PCF8812 Display
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 84
#define HEIGHT 48
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_pcd8544_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
0x006, /* temp. control: b10 = 2 */
0x013, /* bias system 1:48 */
0x0c0, /* medium Vop */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00c, /* display on, normal operation */
U8G_ESC_DLY(100), /* delay 100 ms */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00d, /* display on, invert */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00c, /* display on, normal */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_pcd8544_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00c, /* display on, normal */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_pcd8544_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x008, /* display blank */
0x024, /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_pcd8544_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* command mode */
u8g_SetChipSelect(u8g, dev, 1);
u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */
u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
/* the contrast adjustment does not work, needs to be analysed */
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_SetChipSelect(u8g, dev, 1);
u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */
u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) );
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_pcd8544_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_pcd8544_84x48_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_HW_SPI);

@ -0,0 +1,138 @@
/*
u8g_dev_pcf8812_96x65.c
Display: Nokia 96x65
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
om6206 comaptible to pcf8812 ?
Status: Tested
Display Controller Seen in
LPH7366 (9 pins, 84x48) PCD8544 Nokia 5110 / 5120 / 5130 / 5160 / 6110 / 6150
LPH7677 (8 pins, 84x48) PCD8544 Nokia 3210
LPH7779 (8 pins, 84x48) PCD8544 Nokia 3310 / 3315 / 3330 / 3110, also 3410?
??? PCD8544 Nokia 5110 / 6110
LPH7690 ? (96x65) PCF8455/OM6202 Nokia 3410
LPH7690 ? (96x65?) SED1565/S1D15605 Nokia 7110 / 3510?
LPH7690 ??? Nokia 6210
*/
#include "u8g.h"
#define WIDTH 96
#define HEIGHT 65
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_pcf8812_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
0x006, /* temp. control: b10 = 2 */
0x013, /* bias system 1:48 */
0x080 | 0x040, /* medium Vop */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00c, /* display on, normal operation */
U8G_ESC_DLY(100), /* delay 100 ms */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00d, /* display on, invert */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
0x00c, /* display on, normal */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_pcf8812_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcf8812_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* command mode */
u8g_SetChipSelect(u8g, dev, 1);
u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */
u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
/* mirrored output, not tested*/
/*
{
uint8_t i = pb->width;
while( i > 0 )
{
i--;
u8g_WriteByte(u8g, dev, ((unsigned char *)pb->buf)[i] );
}
}
*/
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
/* the contrast adjustment does not work, needs to be analysed */
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_SetChipSelect(u8g, dev, 1);
u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */
u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) );
u8g_SetChipSelect(u8g, dev, 0);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
/* u8g_com_arduino_sw_spi_fn does not work, too fast??? */
U8G_PB_DEV(u8g_dev_pcf8812_96x65_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcf8812_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_pcf8812_96x65_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcf8812_fn, U8G_COM_HW_SPI);

@ -0,0 +1,107 @@
/*
u8g_dev_sbn1661_122x32.c
WG12232 display with 2xSBN1661 / SED1520 controller (122x32 display)
At the moment only available in the Arduino Environment
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 122
#define HEIGHT 32
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_sbn1661_122x32_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip 1 */
0x0af, /* display on */
0x0c0, /* display start at line 0 */
0x0a0, /* a0: ADC forward, a1: ADC reverse */
0x0a9, /* a8: 1/16, a9: 1/32 duty */
U8G_ESC_CS(2), /* enable chip 2 */
0x0af, /* display on */
0x0c0, /* display start at line 0 */
0x0a0, /* a0: ADC forward, a1: ADC reverse */
0x0a9, /* a8: 1/16, a9: 1/32 duty */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* command mode */
u8g_SetChipSelect(u8g, dev, 1);
u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */
u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/2, pb->buf);
u8g_SetAddress(u8g, dev, 0); /* command mode */
u8g_SetChipSelect(u8g, dev, 2);
u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */
u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/2, WIDTH/2+(uint8_t *)pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
break;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
/* u8g_com_arduino_sw_spi_fn does not work, too fast??? */
U8G_PB_DEV(u8g_dev_sbn1661_122x32 , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn);

@ -0,0 +1,289 @@
/*
u8g_dev_ssd1306_128x32.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 Feb 2013: Fixed, Issue 147
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 32
#define PAGE_HEIGHT 8
/* init sequence adafruit 128x32 OLED (NOT TESTED) */
static const uint8_t u8g_dev_ssd1306_128x32_adafruit1_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x010, /* [1] charge pump setting (p62): 0x014 enable, 0x010 disable */
0x020, 0x000, /* */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x09f, /* [1] set contrast control */
0x0d9, 0x022, /* [1] pre-charge period 0x022/f1*/
0x0db, 0x040, /* vcomh deselect level */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* init sequence adafruit 128x32 OLED (NOT TESTED) */
static const uint8_t u8g_dev_ssd1306_128x32_adafruit2_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
0x020, 0x000, /* */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x0cf, /* [2] set contrast control */
0x0d9, 0x0f1, /* [2] pre-charge period 0x022/f1*/
0x0db, 0x040, /* vcomh deselect level */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* init sequence adafruit 128x32 OLED (TESTED - WORKING 23.02.13), like adafruit3, but with page addressing mode */
static const uint8_t u8g_dev_ssd1306_128x32_adafruit3_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x01f, /* Feb 23, 2013: 128x32 OLED: 0x01f, 128x32 OLED 0x03f */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
0x020, 0x002, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), Feb 23, 2013: 128x32 OLED: 0x002, 128x32 OLED 0x012 */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x002, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x0cf, /* [2] set contrast control */
0x0d9, 0x0f1, /* [2] pre-charge period 0x022/f1*/
0x0db, 0x040, /* vcomh deselect level */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* init sequence Univision datasheet (NOT TESTED) */
static const uint8_t u8g_dev_ssd1306_128x32_univision_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* multiplex ratio */
0x0d3, 0x000, /* display offset */
0x040, /* start line */
0x08d, 0x010, /* charge pump setting (p62): 0x014 enable, 0x010 disable */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x09f, /* set contrast control */
0x0d9, 0x022, /* pre-charge period */
0x0db, 0x040, /* vcomh deselect level */
0x022, 0x000, /* page addressing mode WRONG: 3 byte cmd! */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* select one init sequence here */
//define u8g_dev_ssd1306_128x32_init_seq u8g_dev_ssd1306_128x32_univision_init_seq
//define u8g_dev_ssd1306_128x32_init_seq u8g_dev_ssd1306_128x32_adafruit1_init_seq
//define u8g_dev_ssd1306_128x32_init_seq u8g_dev_ssd1306_128x32_adafruit2_init_seq
#define u8g_dev_ssd1306_128x32_init_seq u8g_dev_ssd1306_128x32_adafruit3_init_seq
static const uint8_t u8g_dev_ssd1306_128x32_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr. to 0 */
0x000, /* set lower 4 bit of the col adr. to 4 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ssd1306_128x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1306_128x32_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1306_128x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x32_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_128x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x32_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_128x32_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x32_fn, U8G_COM_SSD_I2C);
uint8_t u8g_dev_ssd1306_128x32_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1306_128x32_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x32_2x_buf};
u8g_dev_t u8g_dev_ssd1306_128x32_2x_sw_spi = { u8g_dev_ssd1306_128x32_2x_fn, &u8g_dev_ssd1306_128x32_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1306_128x32_2x_hw_spi = { u8g_dev_ssd1306_128x32_2x_fn, &u8g_dev_ssd1306_128x32_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1306_128x32_2x_i2c = { u8g_dev_ssd1306_128x32_2x_fn, &u8g_dev_ssd1306_128x32_2x_pb, U8G_COM_SSD_I2C };

@ -0,0 +1,412 @@
/*
u8g_dev_ssd1306_128x64.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
/* init sequence adafruit 128x64 OLED (NOT TESTED) */
static const uint8_t u8g_dev_ssd1306_128x64_adafruit1_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x010, /* [1] charge pump setting (p62): 0x014 enable, 0x010 disable */
0x020, 0x000, /* */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x09f, /* [1] set contrast control */
0x0d9, 0x022, /* [1] pre-charge period 0x022/f1*/
0x0db, 0x040, /* vcomh deselect level */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* init sequence adafruit 128x64 OLED (NOT TESTED) */
static const uint8_t u8g_dev_ssd1306_128x64_adafruit2_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
0x020, 0x000, /* */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x0cf, /* [2] set contrast control */
0x0d9, 0x0f1, /* [2] pre-charge period 0x022/f1*/
0x0db, 0x040, /* vcomh deselect level */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* init sequence adafruit 128x64 OLED (NOT TESTED), like adafruit3, but with page addressing mode */
static const uint8_t u8g_dev_ssd1306_128x64_adafruit3_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
0x020, 0x002, /* 2012-05-27: page addressing mode */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x0cf, /* [2] set contrast control */
0x0d9, 0x0f1, /* [2] pre-charge period 0x022/f1*/
0x0db, 0x040, /* vcomh deselect level */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* init sequence Univision datasheet (NOT TESTED) */
static const uint8_t u8g_dev_ssd1306_128x64_univision_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x03f, /* multiplex ratio */
0x0d3, 0x000, /* display offset */
0x040, /* start line */
0x08d, 0x010, /* charge pump setting (p62): 0x014 enable, 0x010 disable */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
0x081, 0x09f, /* set contrast control */
0x0d9, 0x022, /* pre-charge period */
0x0db, 0x040, /* vcomh deselect level */
0x022, 0x000, /* page addressing mode WRONG: 3 byte cmd! */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* select one init sequence here */
//#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_univision_init_seq
//#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit1_init_seq
// 26. Apr 2014: in this thead: http://forum.arduino.cc/index.php?topic=234930.msg1696754;topicseen#msg1696754
// it is mentiond, that adafruit2_init_seq works better --> this will be used by the ssd1306_adafruit device
//#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit2_init_seq
#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit3_init_seq
static const uint8_t u8g_dev_ssd1306_128x64_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x000, /* set lower 4 bit of the col adr to 0 */
U8G_ESC_END /* end of sequence */
};
/* the sh1106 is compatible to the ssd1306, but is 132x64. display seems to be centered */
static const uint8_t u8g_dev_sh1106_128x64_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x002, /* set lower 4 bit of the col adr to 2 (centered display with sh1106) */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ssd1306_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_adafruit2_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1306_adafruit_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_sh1106_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1306_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_sh1106_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1306_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SSD_I2C);
U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_SSD_I2C);
uint8_t u8g_dev_ssd1306_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1306_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x64_2x_buf};
u8g_dev_t u8g_dev_ssd1306_128x64_2x_sw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1306_128x64_2x_hw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SSD_I2C };
U8G_PB_DEV(u8g_dev_sh1106_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_sh1106_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_sh1106_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_SSD_I2C);
uint8_t u8g_dev_sh1106_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_sh1106_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_sh1106_128x64_2x_buf};
u8g_dev_t u8g_dev_sh1106_128x64_2x_sw_spi = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_sh1106_128x64_2x_hw_spi = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SSD_I2C };

@ -0,0 +1,187 @@
/*
u8g_dev_ssd1306_64x48.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 64
#define HEIGHT 48
#define PAGE_HEIGHT 8
/* init sequence buydisplay.com 0.66" 64x48 OLED */
/* http://www.buydisplay.com/download/manual/ER-OLED0.66-1_Series_Datasheet.pdf */
static const uint8_t u8g_dev_ssd1306_64x48_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
0x0a8, 0x02f, /* Multiplex Ration, Jul 12, 2015: From 0.66" OLED datasheet */
0x0d3, 0x000, /* */
0x040, /* start line */
0x08d, 0x014, /* charge pump setting (p62): 0x014 enable, 0x010 disable */
//0x020, 0x002, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), Feb 23, 2013: 64x48 OLED: 0x002, 64x48 OLED 0x012 */
0x0a1, /* segment remap a0/a1*/
0x0c8, /* c0: scan dir normal, c8: reverse */
0x0da, 0x012, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), Jul 12, 2015: From 0.66" OLED datasheet */
0x081, 0x0cf, /* set contrast control */
0x0d9, 0x022, /* pre-charge period 0x022/f1, from 0.66" OLED datasheet */
0x0db, 0x000, /* vcomh deselect level, from 0.66" OLED datasheet */
0x02e, /* 2012-05-27: Deactivate scroll */
0x0a4, /* output ram to display */
0x0a6, /* none inverted normal display mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1306_64x48_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010+2, /* set upper 4 bit of the col adr. to 0, 0.66" OLED starts with offset 32 */
0x000, /* set lower 4 bit of the col adr. to 4 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ssd1306_64x48_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_64x48_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_64x48_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1306_64x48_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_64x48_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_64x48_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_64x48_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1306_64x48_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_64x48_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_64x48_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_64x48_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1306_64x48_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_64x48_fn, U8G_COM_SSD_I2C);
uint8_t u8g_dev_ssd1306_64x48_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1306_64x48_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_64x48_2x_buf};
u8g_dev_t u8g_dev_ssd1306_64x48_2x_sw_spi = { u8g_dev_ssd1306_64x48_2x_fn, &u8g_dev_ssd1306_64x48_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1306_64x48_2x_hw_spi = { u8g_dev_ssd1306_64x48_2x_fn, &u8g_dev_ssd1306_64x48_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1306_64x48_2x_i2c = { u8g_dev_ssd1306_64x48_2x_fn, &u8g_dev_ssd1306_64x48_2x_pb, U8G_COM_SSD_I2C };

@ -0,0 +1,142 @@
/*
u8g_dev_ssd1309_128x64.c
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
/* ssd1309 ini sequence*/
static const uint8_t u8g_dev_ssd1309_128x64_init_seq[] PROGMEM={
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0xfd,0x12, /*Command Lock */
0xae, /*Set Display Off */
0xd5,0xa0, /*set Display Clock Divide Ratio/Oscillator Frequency */
0xa8,0x3f, /*Set Multiplex Ratio */
0x3d,0x00, /*Set Display Offset*/
0x40, /*Set Display Start Line*/
0xa1, /*Set Segment Re-Map*/
0xc8, /*Set COM Output Scan Direction*/
0xda,0x12, /*Set COM Pins Hardware Configuration*/
0x81,0xdf, /*Set Current Control */
0xd9,0x82, /*Set Pre-Charge Period */
0xdb,0x34, /*Set VCOMH Deselect Level */
0xa4, /*Set Entire Display On/Off */
0xa6, /*Set Normal/Inverse Display*/
U8G_ESC_VCC(1), /*Power up VCC & Stabilized */
U8G_ESC_DLY(50),
0xaf, /*Set Display On */
U8G_ESC_DLY(50),
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
/* select one init sequence here */
#define u8g_dev_ssd1309_128x64_init_seq u8g_dev_ssd1309_128x64_init_seq
static const uint8_t u8g_dev_ssd1309_128x64_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x000, /* set lower 4 bit of the col adr to 4 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) ); /* 11 Jul 2015: fixed contrast calculation */
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1309_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1309_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1309_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SSD_I2C);

@ -0,0 +1,338 @@
/*
u8g_dev_ssd1322_nhd31oled_bw.c
1-Bit (BW) Driver for SSD1322 Controller (OLED Display)
Tested with NHD-3.12-25664
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#include "u8g.h"
/* width must be multiple of 8, largest value is 248 unless u8g 16 bit mode is enabled */
#if defined(U8G_16BIT)
#define WIDTH 256
#else
#define WIDTH 248
#endif
#define HEIGHT 64
#define PAGE_HEIGHT 8
/*
http://www.newhavendisplay.com/app_notes/OLED_25664.txt
http://www.newhavendisplay.com/forum/viewtopic.php?f=15&t=3758
*/
static const uint8_t u8g_dev_ssd1322_1bit_nhd_312_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_ADR(0), /* instruction mode */
0x0fd, /* lock command */
U8G_ESC_ADR(1), /* data mode */
0x012, /* unlock */
U8G_ESC_ADR(0), /* instruction mode */
0x0ae, /* display off, sleep mode */
U8G_ESC_ADR(0), /* instruction mode */
0x0b3,
U8G_ESC_ADR(1), /* data mode */
0x091, /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
U8G_ESC_ADR(0), /* instruction mode */
0x0ca, /* multiplex ratio */
U8G_ESC_ADR(1), /* data mode */
0x03f, /* 1/64 Duty (0x0F~0x3F) */
U8G_ESC_ADR(0), /* instruction mode */
0x0a2,
U8G_ESC_ADR(1), /* data mode */
0x000, /* display offset, shift mapping ram counter */
U8G_ESC_ADR(0), /* instruction mode */
0x0a1,
U8G_ESC_ADR(1), /* data mode */
0x000, /* display start line */
U8G_ESC_ADR(0), /* instruction mode */
0x0a0, /* Set Re-Map / Dual COM Line Mode */
U8G_ESC_ADR(1), /* data mode */
0x014, /* was 0x014 */
0x011, /* was 0x011 */
U8G_ESC_ADR(0), /* instruction mode */
0x0ab,
U8G_ESC_ADR(1), /* data mode */
0x001, /* Enable Internal VDD Regulator */
U8G_ESC_ADR(0), /* instruction mode */
0x0b4, /* Display Enhancement A */
U8G_ESC_ADR(1), /* data mode */
0x0a0,
0x005|0x0fd,
U8G_ESC_ADR(0), /* instruction mode */
0x0c1, /* contrast */
U8G_ESC_ADR(1), /* data mode */
0x09f,
U8G_ESC_ADR(0), /* instruction mode */
0x0c7, /* Set Scale Factor of Segment Output Current Control */
U8G_ESC_ADR(1), /* data mode */
0x00f,
U8G_ESC_ADR(0), /* instruction mode */
0x0b9, /* linear gray scale */
U8G_ESC_ADR(0), /* instruction mode */
0x0b1, /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
U8G_ESC_ADR(1), /* data mode */
0x0e2,
U8G_ESC_ADR(0), /* instruction mode */
0x0d1, /* Display Enhancement B */
U8G_ESC_ADR(1), /* data mode */
0x082|0x020,
0x020,
U8G_ESC_ADR(0), /* instruction mode */
0x0bb, /* precharge voltage */
U8G_ESC_ADR(1), /* data mode */
0x01f,
U8G_ESC_ADR(0), /* instruction mode */
0x0b6, /* precharge period */
U8G_ESC_ADR(1), /* data mode */
0x008,
U8G_ESC_ADR(0), /* instruction mode */
0x0be, /* vcomh */
U8G_ESC_ADR(1), /* data mode */
0x007,
U8G_ESC_ADR(0), /* instruction mode */
0x0a6, /* normal display */
U8G_ESC_ADR(0), /* instruction mode */
0x0a9, /* exit partial display */
U8G_ESC_ADR(0), /* instruction mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1322_1bit_nhd_312_prepare_page_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
U8G_ESC_ADR(1), /* data mode */
0x01c, /* start at column 0 */
0x05b, /* end column */
U8G_ESC_ADR(0), /* instruction mode */
0x075, /* row address... */
U8G_ESC_ADR(1), /* data mode */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1322_1bit_prepare_row(u8g_t *u8g, u8g_dev_t *dev, uint8_t delta_row)
{
uint8_t row = ((u8g_pb_t *)(dev->dev_mem))->p.page;
row *= ((u8g_pb_t *)(dev->dev_mem))->p.page_height;
row += delta_row;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_1bit_nhd_312_prepare_page_seq);
u8g_WriteByte(u8g, dev, row); /* start at the selected row */
u8g_WriteByte(u8g, dev, row+1); /* end within the selected row */
u8g_SetAddress(u8g, dev, 0); /* instruction mode mode */
u8g_WriteByte(u8g, dev, 0x05c); /* write to ram */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ssd1322_nhd31oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_1bit_nhd_312_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 3;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1322_1bit_prepare_row(u8g, dev, i); /* this will also enable chip select */
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x0ff);
u8g_WriteByte(u8g, dev, 0x0ff);
#endif
u8g_WriteSequenceBWTo16GrDevice(u8g, dev, cnt, p);
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x0ff);
u8g_WriteByte(u8g, dev, 0x0ff);
#endif
u8g_MicroDelay(); // for DUE?
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_MicroDelay(); // for DUE?
u8g_SetChipSelect(u8g, dev, 0);
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_1bit_nhd_312_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 3;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1322_1bit_prepare_row(u8g, dev, i); /* this will also enable chip select */
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x0ff);
u8g_WriteByte(u8g, dev, 0x0ff);
#endif
u8g_WriteSequenceBWTo16GrDevice(u8g, dev, cnt, p);
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x0ff);
u8g_WriteByte(u8g, dev, 0x0ff);
#endif
u8g_MicroDelay(); // for DUE?
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x0c1); /* 21 May 2013, fixed contrast command */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_bw_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_bw_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_bw_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_bw_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_bw_parallel , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_bw_fn, U8G_COM_FAST_PARALLEL);
#define DWIDTH (WIDTH*2)
uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_buf[DWIDTH] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1322_nhd31oled_2x_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1322_nhd31oled_2x_bw_buf};
u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_bw_sw_spi = { u8g_dev_ssd1322_nhd31oled_2x_bw_fn, &u8g_dev_ssd1322_nhd31oled_2x_bw_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_bw_hw_spi = { u8g_dev_ssd1322_nhd31oled_2x_bw_fn, &u8g_dev_ssd1322_nhd31oled_2x_bw_pb, U8G_COM_HW_SPI };

@ -0,0 +1,338 @@
/*
u8g_dev_ssd1322_nhd31oled_gr.c
2-Bit (4L) Driver for SSD1322 Controller (OLED Display)
Tested with NHD-3.12-25664
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#include "u8g.h"
/* width must be multiple of 8, largest value is 248 unless u8g 16 bit mode is enabled */
#if defined(U8G_16BIT)
#define WIDTH 256
#else
#define WIDTH 248
#endif
#define HEIGHT 64
//#define PAGE_HEIGHT 8
/*
http://www.newhavendisplay.com/app_notes/OLED_25664.txt
http://www.newhavendisplay.com/forum/viewtopic.php?f=15&t=3758
*/
static const uint8_t u8g_dev_ssd1322_2bit_nhd_312_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_ADR(0), /* instruction mode */
0x0fd, /* lock command */
U8G_ESC_ADR(1), /* data mode */
0x012, /* unlock */
U8G_ESC_ADR(0), /* instruction mode */
0x0ae, /* display off, sleep mode */
U8G_ESC_ADR(0), /* instruction mode */
0x0b3,
U8G_ESC_ADR(1), /* data mode */
0x091, /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
U8G_ESC_ADR(0), /* instruction mode */
0x0ca, /* multiplex ratio */
U8G_ESC_ADR(1), /* data mode */
0x03f, /* 1/64 Duty (0x0F~0x3F) */
U8G_ESC_ADR(0), /* instruction mode */
0x0a2,
U8G_ESC_ADR(1), /* data mode */
0x000, /* display offset, shift mapping ram counter */
U8G_ESC_ADR(0), /* instruction mode */
0x0a1,
U8G_ESC_ADR(1), /* data mode */
0x000, /* display start line */
U8G_ESC_ADR(0), /* instruction mode */
0x0a0, /* Set Re-Map / Dual COM Line Mode */
U8G_ESC_ADR(1), /* data mode */
0x014, /* was 0x014 */
0x011, /* was 0x011 */
U8G_ESC_ADR(0), /* instruction mode */
0x0ab,
U8G_ESC_ADR(1), /* data mode */
0x001, /* Enable Internal VDD Regulator */
U8G_ESC_ADR(0), /* instruction mode */
0x0b4, /* Display Enhancement A */
U8G_ESC_ADR(1), /* data mode */
0x0a0,
0x005|0x0fd,
U8G_ESC_ADR(0), /* instruction mode */
0x0c1, /* contrast */
U8G_ESC_ADR(1), /* data mode */
0x09f,
U8G_ESC_ADR(0), /* instruction mode */
0x0c7, /* Set Scale Factor of Segment Output Current Control */
U8G_ESC_ADR(1), /* data mode */
0x00f,
U8G_ESC_ADR(0), /* instruction mode */
0x0b9, /* linear gray scale */
U8G_ESC_ADR(0), /* instruction mode */
0x0b1, /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
U8G_ESC_ADR(1), /* data mode */
0x0e2,
U8G_ESC_ADR(0), /* instruction mode */
0x0d1, /* Display Enhancement B */
U8G_ESC_ADR(1), /* data mode */
0x082|0x020,
0x020,
U8G_ESC_ADR(0), /* instruction mode */
0x0bb, /* precharge voltage */
U8G_ESC_ADR(1), /* data mode */
0x01f,
U8G_ESC_ADR(0), /* instruction mode */
0x0b6, /* precharge period */
U8G_ESC_ADR(1), /* data mode */
0x008,
U8G_ESC_ADR(0), /* instruction mode */
0x0be, /* vcomh */
U8G_ESC_ADR(1), /* data mode */
0x007,
U8G_ESC_ADR(0), /* instruction mode */
0x0a6, /* normal display */
U8G_ESC_ADR(0), /* instruction mode */
0x0a9, /* exit partial display */
U8G_ESC_ADR(0), /* instruction mode */
0x0af, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1322_2bit_nhd_312_prepare_page_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
U8G_ESC_ADR(1), /* data mode */
0x01c, /* start at column 0 */
0x05b, /* end column */
U8G_ESC_ADR(0), /* instruction mode */
0x075, /* row address... */
U8G_ESC_ADR(1), /* data mode */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1322_2bit_prepare_row(u8g_t *u8g, u8g_dev_t *dev, uint8_t delta_row)
{
uint8_t row = ((u8g_pb_t *)(dev->dev_mem))->p.page;
row *= ((u8g_pb_t *)(dev->dev_mem))->p.page_height;
row += delta_row;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_2bit_nhd_312_prepare_page_seq);
u8g_WriteByte(u8g, dev, row); /* start at the selected row */
u8g_WriteByte(u8g, dev, row+1); /* end within the selected row */
u8g_SetAddress(u8g, dev, 0); /* instruction mode mode */
u8g_WriteByte(u8g, dev, 0x05c); /* write to ram */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_ssd1322_nhd31oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_2bit_nhd_312_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 2;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1322_2bit_prepare_row(u8g, dev, i); /* this will also enable chip select */
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x00);
u8g_WriteByte(u8g, dev, 0x00);
#endif
u8g_WriteSequence4LTo16GrDevice(u8g, dev, cnt, p);
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x00);
u8g_WriteByte(u8g, dev, 0x00);
#endif
u8g_MicroDelay(); // for DUE?
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_MicroDelay(); // for DUE?
u8g_SetChipSelect(u8g, dev, 0);
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8h2_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_2bit_nhd_312_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 2; /* 23 Oct 2013, changed to 2 */
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1322_2bit_prepare_row(u8g, dev, i); /* this will also enable chip select */
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x00);
u8g_WriteByte(u8g, dev, 0x00);
#endif
u8g_WriteSequence4LTo16GrDevice(u8g, dev, cnt, p);
#if !defined(U8G_16BIT)
u8g_WriteByte(u8g, dev, 0x00);
u8g_WriteByte(u8g, dev, 0x00);
#endif
u8g_MicroDelay(); // for DUE?
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16h2_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_sw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_hw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_parallel , WIDTH, HEIGHT, 4, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_FAST_PARALLEL);
#define DWIDTH (WIDTH*2)
uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_buf[DWIDTH] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1322_nhd31oled_2x_gr_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1322_nhd31oled_2x_gr_buf};
u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_sw_spi = { u8g_dev_ssd1322_nhd31oled_2x_gr_fn, &u8g_dev_ssd1322_nhd31oled_2x_gr_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_hw_spi = { u8g_dev_ssd1322_nhd31oled_2x_gr_fn, &u8g_dev_ssd1322_nhd31oled_2x_gr_pb, U8G_COM_HW_SPI };

@ -0,0 +1,263 @@
/*
u8g_dev_ssd1325_nhd27oled_bw.c
1-Bit (BW) Driver for SSD1325 Controller (OLED Display)
Tested with NHD-2.7-12864UCY3
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#ifdef OBSOLETE_CODE
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
/* http://www.newhavendisplay.com/app_notes/OLED_2_7_12864.txt */
static const uint8_t u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0b3, 0x091, /* set display clock divide ratio/oscillator frequency (set clock as 135 frames/sec) */
0x0a8, 0x03f, /* multiplex ratio: 0x03f * 1/64 duty */
0x0a2, 0x04c, /* display offset, shift mapping ram counter */
0x0a1, 0x000, /* display start line */
0x0ad, 0x002, /* master configuration: disable embedded DC-DC, enable internal VCOMH */
0x0a0, 0x056, /* remap configuration, vertical address increment, enable nibble remap (upper nibble is left) */
0x086, /* full current range (0x084, 0x085, 0x086) */
0x0b8, /* set gray scale table */
0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x065, 0x076,
0x081, 0x070, /* contrast, brightness, 0..128, Newhaven: 0x040 */
0x0b2, 0x051, /* frame frequency (row period) */
0x0b1, 0x055, /* phase length */
0x0bc, 0x010, /* pre-charge voltage level */
0x0b4, 0x002, /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0b0, 0x028, /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0be, 0x01c, /* VCOMH voltage */
0x0bf, 0x002|0x00d, /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0a5, /* all pixel on */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display mode */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_prepare_page_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
0x000, /* start at column 0 */
0x03f, /* end at column 63 (which is y == 127), because there are two pixel in one column */
0x075, /* row address... */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1325_1bit_prepare_page(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t page = ((u8g_pb_t *)(dev->dev_mem))->p.page;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_prepare_page_seq);
page <<= 3;
u8g_WriteByte(u8g, dev, page); /* start at the selected page */
page += 7;
u8g_WriteByte(u8g, dev, page); /* end within the selected page */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static void u8g_dev_ssd1325_1bit_2x_prepare_page(u8g_t *u8g, u8g_dev_t *dev, uint8_t is_odd)
{
uint8_t page = ((u8g_pb_t *)(dev->dev_mem))->p.page;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_prepare_page_seq);
page <<= 1;
page += is_odd;
page <<= 3;
u8g_WriteByte(u8g, dev, page); /* start at the selected page */
page += 7;
u8g_WriteByte(u8g, dev, page); /* end within the selected page */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
/* assumes row autoincrement and activated nibble remap */
#ifdef OLD
static void _OLD_u8g_dev_ssd1325_1bit_write_16_pixel(u8g_t *u8g, u8g_dev_t *dev, uint8_t left, uint8_t right)
{
uint8_t d, cnt;
cnt = 8;
do
{
d = 0;
if ( left & 1 )
d |= 0x0f0;
if ( right & 1 )
d |= 0x00f;
u8g_WriteByte(u8g, dev, d);
left >>= 1;
right >>= 1;
cnt--;
}while ( cnt > 0 );
}
#endif
static void u8g_dev_ssd1325_1bit_write_16_pixel(u8g_t *u8g, u8g_dev_t *dev, uint8_t left, uint8_t right)
{
uint8_t d, cnt;
static uint8_t buf[8];
cnt = 8;
do
{
d = 0;
if ( left & 128 )
d |= 0x0f0;
if ( right & 128 )
d |= 0x00f;
cnt--;
buf[cnt] = d;
left <<= 1;
right <<= 1;
}while ( cnt > 0 );
u8g_WriteSequence(u8g, dev, 8, buf);
}
static void u8g_dev_ssd1325_1bit_write_buffer(u8g_t *u8g, u8g_dev_t *dev, uint8_t is_odd)
{
uint8_t cnt, left, right;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
ptr = pb->buf;
cnt = pb->width;
if ( is_odd )
ptr += cnt;
cnt >>= 1;
do
{
left = *ptr++;
right = *ptr++;
u8g_dev_ssd1325_1bit_write_16_pixel(u8g, dev, left, right);
cnt--;
} while( cnt > 0 );
}
uint8_t u8g_dev_ssd1325_nhd27oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_dev_ssd1325_1bit_prepare_page(u8g, dev);
u8g_dev_ssd1325_1bit_write_buffer(u8g, dev, 0);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
break;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1325_nhd27oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_dev_ssd1325_1bit_2x_prepare_page(u8g, dev, 0);
u8g_dev_ssd1325_1bit_write_buffer(u8g, dev, 0);
u8g_dev_ssd1325_1bit_2x_prepare_page(u8g, dev, 1);
u8g_dev_ssd1325_1bit_write_buffer(u8g, dev, 1);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
break;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
/* disabled, see bw_new.c */
/*
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_bw_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1325_nhd27oled_bw_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_bw_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1325_nhd27oled_bw_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_bw_parallel , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1325_nhd27oled_bw_fn, U8G_COM_FAST_PARALLEL);
*/
/*
uint8_t u8g_dev_ssd1325_nhd27oled_2x_bw_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1325_nhd27oled_2x_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1325_nhd27oled_2x_bw_buf};
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_sw_spi = { u8g_dev_ssd1325_nhd27oled_2x_bw_fn, &u8g_dev_ssd1325_nhd27oled_2x_bw_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_hw_spi = { u8g_dev_ssd1325_nhd27oled_2x_bw_fn, &u8g_dev_ssd1325_nhd27oled_2x_bw_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_parallel = { u8g_dev_ssd1325_nhd27oled_2x_bw_fn, &u8g_dev_ssd1325_nhd27oled_2x_bw_pb, U8G_COM_FAST_PARALLEL };
*/
#endif

@ -0,0 +1,232 @@
/*
u8g_dev_ssd1325_nhd27oled_bw.c
1-Bit (BW) Driver for SSD1325 Controller (OLED Display)
Horizontal architecture, completly rewritten
Tested with NHD-2.7-12864UCY3
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#include "u8g.h"
/* width must be multiple of 8, largest value is 248 unless u8g 16 bit mode is enabled */
#define WIDTH 128
#define HEIGHT 64
/* http://www.newhavendisplay.com/app_notes/OLED_2_7_12864.txt */
static const uint8_t u8g_dev_ssd1325_nhd_27_12864_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0b3, 0x091, /* set display clock divide ratio/oscillator frequency (set clock as 135 frames/sec) */
0x0a8, 0x03f, /* multiplex ratio: 0x03f * 1/64 duty */
0x0a2, 0x04c, /* display offset, shift mapping ram counter */
0x0a1, 0x000, /* display start line */
0x0ad, 0x002, /* master configuration: disable embedded DC-DC, enable internal VCOMH */
0x0a0, 0x052, /* remap configuration, horizontal address increment (bit 2 = 0), enable nibble remap (upper nibble is left, bit 1 = 1) */
0x086, /* full current range (0x084, 0x085, 0x086) */
0x0b8, /* set gray scale table */
0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x065, 0x076,
0x081, 0x070, /* contrast, brightness, 0..128, Newhaven: 0x040 */
0x0b2, 0x051, /* frame frequency (row period) */
0x0b1, 0x055, /* phase length */
0x0bc, 0x010, /* pre-charge voltage level */
0x0b4, 0x002, /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0b0, 0x028, /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0be, 0x01c, /* VCOMH voltage */
0x0bf, 0x002|0x00d, /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0a4, /* normal display mode */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1325_prepare_row_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
0x000, /* start at column 0 */
0x03f, /* end at column 63 (which is y == 127), because there are two pixel in one column */
0x075, /* row address... */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1325_prepare_row(u8g_t *u8g, u8g_dev_t *dev, uint8_t delta_row)
{
uint8_t row = ((u8g_pb_t *)(dev->dev_mem))->p.page;
row *= ((u8g_pb_t *)(dev->dev_mem))->p.page_height;
row += delta_row;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_prepare_row_seq);
u8g_WriteByte(u8g, dev, row); /* start at the selected row */
u8g_WriteByte(u8g, dev, row+1); /* end within the selected row */
//u8g_SetAddress(u8g, dev, 0); /* instruction mode mode */
//u8g_WriteByte(u8g, dev, 0x05c); /* write to ram */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static uint8_t u8g_dev_ssd1325_nhd27oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
//case U8G_DEV_MSG_IS_BBX_INTERSECTION:
// return u8g_pb_IsIntersection((u8g_pb_t *)(dev->dev_mem), (u8g_dev_arg_bbx_t *)arg);
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_nhd_27_12864_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 3;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1325_prepare_row(u8g, dev, i); /* this will also enable chip select */
u8g_WriteSequenceBWTo16GrDevice(u8g, dev, cnt, p);
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
static uint8_t u8g_dev_ssd1325_nhd27oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_nhd_27_12864_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 3;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1325_prepare_row(u8g, dev, i); /* this will also enable chip select */
u8g_WriteSequenceBWTo16GrDevice(u8g, dev, cnt, p);
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_bw_sw_spi , WIDTH, HEIGHT, 8, u8g_dev_ssd1325_nhd27oled_bw_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_bw_hw_spi , WIDTH, HEIGHT, 8, u8g_dev_ssd1325_nhd27oled_bw_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_bw_parallel , WIDTH, HEIGHT, 8, u8g_dev_ssd1325_nhd27oled_bw_fn, U8G_COM_FAST_PARALLEL);
uint8_t u8g_dev_ssd1325_nhd27oled_2x_bw_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1325_nhd27oled_2x_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1325_nhd27oled_2x_bw_buf};
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_sw_spi = { u8g_dev_ssd1325_nhd27oled_2x_bw_fn, &u8g_dev_ssd1325_nhd27oled_2x_bw_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_hw_spi = { u8g_dev_ssd1325_nhd27oled_2x_bw_fn, &u8g_dev_ssd1325_nhd27oled_2x_bw_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_parallel = { u8g_dev_ssd1325_nhd27oled_2x_bw_fn, &u8g_dev_ssd1325_nhd27oled_2x_bw_pb, U8G_COM_FAST_PARALLEL };

@ -0,0 +1,255 @@
/*
u8g_dev_ssd1325_nhd27oled_gr.c
2-Bit (gray level) Driver for SSD1325 Controller (OLED Display)
Tested with NHD-2.7-12864UCY3
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#ifdef OBSOLETE_CODE
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
/* http://www.newhavendisplay.com/app_notes/OLED_2_7_12864.txt */
static const uint8_t u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0b3, 0x091, /* set display clock divide ratio/oscillator frequency (set clock as 135 frames/sec) */
0x0a8, 0x03f, /* multiplex ratio: 0x03f * 1/64 duty */
0x0a2, 0x04c, /* display offset, shift mapping ram counter */
0x0a1, 0x000, /* display start line */
0x0ad, 0x002, /* master configuration: disable embedded DC-DC, enable internal VCOMH */
0x0a0, 0x056, /* remap configuration, vertical address increment, enable nibble remap (upper nibble is left) */
0x086, /* full current range (0x084, 0x085, 0x086) */
0x0b8, /* set gray scale table */
//0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x065, 0x076,
0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x077, 0x077, // 4L mode uses 0, 2, 4, 7
0x081, 0x070, /* contrast, brightness, 0..128, Newhaven: 0x040 */
0x0b2, 0x051, /* frame frequency (row period) */
0x0b1, 0x055, /* phase length */
0x0bc, 0x010, /* pre-charge voltage level */
0x0b4, 0x002, /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0b0, 0x028, /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0be, 0x01c, /* VCOMH voltage */
0x0bf, 0x002|0x00d, /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0a5, /* all pixel on */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display mode */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_prepare_page_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
0x000, /* start at column 0 */
0x03f, /* end at column 63 (which is y == 127), because there are two pixel in one column */
0x075, /* row address... */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1325_2bit_prepare_page(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t page = ((u8g_pb_t *)(dev->dev_mem))->p.page;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_prepare_page_seq);
page <<= 2;
u8g_WriteByte(u8g, dev, page); /* start at the selected page */
page += 3;
u8g_WriteByte(u8g, dev, page); /* end within the selected page */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static void u8g_dev_ssd1325_2bit_2x_prepare_page(u8g_t *u8g, u8g_dev_t *dev, uint8_t is_odd)
{
uint8_t page = ((u8g_pb_t *)(dev->dev_mem))->p.page;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_prepare_page_seq);
page <<= 1;
page += is_odd;
page <<= 2;
u8g_WriteByte(u8g, dev, page); /* start at the selected page */
page += 3;
u8g_WriteByte(u8g, dev, page); /* end within the selected page */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
/* assumes row autoincrement and activated nibble remap */
static void u8g_dev_ssd1325_2bit_write_4_pixel(u8g_t *u8g, u8g_dev_t *dev, uint8_t left, uint8_t right)
{
uint8_t d, tmp, cnt;
cnt = 4;
do
{
d = left;
d &= 3;
d <<= 4;
tmp = right;
tmp &= 3;
d |= tmp;
d <<= 2;
u8g_WriteByte(u8g, dev, d);
left >>= 2;
right >>= 2;
cnt--;
}while ( cnt > 0 );
}
static void u8g_dev_ssd1325_2bit_write_buffer(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t cnt, left, right;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
cnt = pb->width;
cnt >>= 1;
ptr = pb->buf;
do
{
left = *ptr++;
right = *ptr++;
u8g_dev_ssd1325_2bit_write_4_pixel(u8g, dev, left, right);
cnt--;
} while( cnt > 0 );
}
static void u8g_dev_ssd1325_2bit_2x_write_buffer(u8g_t *u8g, u8g_dev_t *dev, uint8_t is_odd)
{
uint8_t cnt, left, right;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
ptr = pb->buf;
cnt = pb->width;
if ( is_odd )
ptr += cnt;
cnt >>= 1;
do
{
left = *ptr++;
right = *ptr++;
u8g_dev_ssd1325_2bit_write_4_pixel(u8g, dev, left, right);
cnt--;
} while( cnt > 0 );
}
static uint8_t u8g_dev_ssd1325_nhd27oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_dev_ssd1325_2bit_prepare_page(u8g, dev);
u8g_dev_ssd1325_2bit_write_buffer(u8g, dev);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
}
return u8g_dev_pb8v2_base_fn(u8g, dev, msg, arg);
}
static uint8_t u8g_dev_ssd1325_nhd27oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_dev_ssd1325_2bit_2x_prepare_page(u8g, dev, 0);
u8g_dev_ssd1325_2bit_2x_write_buffer(u8g, dev, 0);
u8g_dev_ssd1325_2bit_2x_prepare_page(u8g, dev, 1);
u8g_dev_ssd1325_2bit_2x_write_buffer(u8g, dev, 1);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
}
return u8g_dev_pb16v2_base_fn(u8g, dev, msg, arg);
}
//U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_gr_sw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1325_nhd27oled_gr_fn, U8G_COM_SW_SPI);
//U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_gr_hw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1325_nhd27oled_gr_fn, U8G_COM_HW_SPI);
//uint8_t u8g_dev_ssd1325_nhd27oled_2x_buf[WIDTH*2] U8G_NOCOMMON ;
//u8g_pb_t u8g_dev_ssd1325_nhd27oled_2x_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1325_nhd27oled_2x_buf};
//u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_sw_spi = { u8g_dev_ssd1325_nhd27oled_2x_gr_fn, &u8g_dev_ssd1325_nhd27oled_2x_pb, U8G_COM_SW_SPI };
//u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_hw_spi = { u8g_dev_ssd1325_nhd27oled_2x_gr_fn, &u8g_dev_ssd1325_nhd27oled_2x_pb, U8G_COM_HW_SPI };
#endif /* OBSOLETE_CODE */

@ -0,0 +1,227 @@
/*
u8g_dev_ssd1325_nhd27oled_gr.c
2-Bit (gray level) Driver for SSD1325 Controller (OLED Display)
Rewritten with new architecture
Tested with NHD-2.7-12864UCY3
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
/* http://www.newhavendisplay.com/app_notes/OLED_2_7_12864.txt */
static const uint8_t u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off, sleep mode */
0x0b3, 0x091, /* set display clock divide ratio/oscillator frequency (set clock as 135 frames/sec) */
0x0a8, 0x03f, /* multiplex ratio: 0x03f * 1/64 duty */
0x0a2, 0x04c, /* display offset, shift mapping ram counter */
0x0a1, 0x000, /* display start line */
0x0ad, 0x002, /* master configuration: disable embedded DC-DC, enable internal VCOMH */
0x0a0, 0x052, /* remap configuration, horizontal address increment (bit 2 = 0), enable nibble remap (upper nibble is left, bit 1 = 1), old values: 0x0a0 0x0a6 */
0x086, /* full current range (0x084, 0x085, 0x086) */
0x0b8, /* set gray scale table */
//0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x065, 0x076,
0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x077, 0x077, // 4L mode uses 0, 2, 4, 7
0x081, 0x070, /* contrast, brightness, 0..128, Newhaven: 0x040 */
0x0b2, 0x051, /* frame frequency (row period) */
0x0b1, 0x055, /* phase length */
0x0bc, 0x010, /* pre-charge voltage level */
0x0b4, 0x002, /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0b0, 0x028, /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0be, 0x01c, /* VCOMH voltage */
0x0bf, 0x002|0x00d, /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0a4, /* normal display mode */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_prepare_page_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
0x000, /* start at column 0 */
0x03f, /* end at column 63 (which is y == 127), because there are two pixel in one column */
0x075, /* row address... */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1325_gr_prepare_row(u8g_t *u8g, u8g_dev_t *dev, uint8_t delta_row)
{
uint8_t row = ((u8g_pb_t *)(dev->dev_mem))->p.page;
row *= ((u8g_pb_t *)(dev->dev_mem))->p.page_height;
row += delta_row;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_prepare_page_seq);
u8g_WriteByte(u8g, dev, row); /* start at the selected row */
u8g_WriteByte(u8g, dev, row+1); /* end within the selected row */
//u8g_SetAddress(u8g, dev, 0); /* instruction mode mode */
//u8g_WriteByte(u8g, dev, 0x05c); /* write to ram */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ae, /* display off */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static uint8_t u8g_dev_ssd1325_nhd27oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 2;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1325_gr_prepare_row(u8g, dev, i); /* this will also enable chip select */
u8g_WriteSequence4LTo16GrDevice(u8g, dev, cnt, p);
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb8h2_base_fn(u8g, dev, msg, arg);
}
static uint8_t u8g_dev_ssd1325_nhd27oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *p = pb->buf;
u8g_uint_t cnt;
cnt = pb->width;
cnt >>= 2;
for( i = 0; i < pb->p.page_height; i++ )
{
u8g_dev_ssd1325_gr_prepare_row(u8g, dev, i); /* this will also enable chip select */
u8g_WriteSequence4LTo16GrDevice(u8g, dev, cnt, p);
u8g_SetChipSelect(u8g, dev, 0);
p+=cnt;
}
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
return 1;
}
return u8g_dev_pb16h2_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_gr_sw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1325_nhd27oled_gr_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1325_nhd27oled_gr_hw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1325_nhd27oled_gr_fn, U8G_COM_HW_SPI);
uint8_t u8g_dev_ssd1325_nhd27oled_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1325_nhd27oled_2x_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1325_nhd27oled_2x_buf};
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_sw_spi = { u8g_dev_ssd1325_nhd27oled_2x_gr_fn, &u8g_dev_ssd1325_nhd27oled_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_hw_spi = { u8g_dev_ssd1325_nhd27oled_2x_gr_fn, &u8g_dev_ssd1325_nhd27oled_2x_pb, U8G_COM_HW_SPI };

@ -0,0 +1,299 @@
/*
u8g_dev_ssd1327_96x96_gr.c
2-Bit (graylevel) Driver for SSD1327 Controller (OLED Display)
Tested with Seedstudio 96x96 Oled (LY120)
http://www.seeedstudio.com/wiki/index.php?title=Twig_-_OLED_96x96
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SSD130x Monochrom OLED Controller
SSD131x Character OLED Controller
SSD132x Graylevel OLED Controller
SSD1331 Color OLED Controller
*/
#include "u8g.h"
#define WIDTH 96
#define HEIGHT 96
#define XOFFSET 8
/*
http://www.seeedstudio.com/wiki/index.php?title=Twig_-_OLED_96x96
*/
static const uint8_t u8g_dev_ssd1327_2bit_96x96_init_seq[] PROGMEM = {
U8G_ESC_DLY(10), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x0fd, 0x012, /* unlock display, usually not required because the display is unlocked after reset */
0x0ae, /* display off, sleep mode */
0x0a8, 0x05f, /* multiplex ratio: 0x05f * 1/64 duty */
0x0a1, 0x000, /* display start line */
0x0a2, 0x060, /* display offset, shift mapping ram counter */
//0x0a2, 0x04c, /* NHD: display offset, shift mapping ram counter */
0x0a0, 0x046, /* remap configuration, vertical address increment, enable nibble remap (upper nibble is left) */
//0x0a0, 0x056, /* NHD: remap configuration, vertical address increment, enable nibble remap (upper nibble is left) */
0x0ab, 0x001, /* Enable internal VDD regulator (RESET) */
0x081, 0x053, /* contrast, brightness, 0..128, Newhaven: 0x040, LY120 0x053, 0x070 seems also ok */
0x0b1, 0x051, /* phase length */
0x0b3, 0x001, /* set display clock divide ratio/oscillator frequency */
0x0b9, /* use linear lookup table */
#if 0
0x0b8, /* set gray scale table */
//0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x065, 0x076,
0x01, 0x011, 0x022, 0x032, 0x043, 0x054, 0x077, 0x077, // 4L mode uses 0, 2, 4, 7
#endif
0x0bc, 0x008, /* pre-charge voltage level */
0x0be, 0x007, /* VCOMH voltage */
0x0b6, 0x001, /* second precharge */
0x0d5, 0x062, /* enable second precharge, internal vsl (bit0 = 0) */
#if 0
// the following commands are not used by the SeeedGrayOLED sequence */
0x0ad, 0x002, /* master configuration: disable embedded DC-DC, enable internal VCOMH */
0x086, /* full current range (0x084, 0x085, 0x086) */
0x0b2, 0x051, /* frame frequency (row period) */
0x0b4, 0x002, /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0b0, 0x028, /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
0x0bf, 0x002|0x00d, /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
#endif
0x0a5, /* all pixel on */
//0x02e, /* no scroll (according to SeeedGrayOLED sequence) */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display mode */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* all pixel on */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display mode */
0x015, /* column address... */
0x008, /* start at column 8, special for the LY120 ??? */
0x037, /* end at column 55, note: there are two pixel in one column */
0x075, /* row address... */
0x008,
0x05f,
U8G_ESC_ADR(1), /* data mode */
0x000f, 0x000f, 0x0000, 0x0000, 0x000f,0x000f,0x0000,0x0000,
0x000f, 0x000f, 0x0000, 0x0000, 0x000f,0x000f,0x0000,0x0000,
0x000f, 0x000f, 0x0000, 0x0000, 0x000f,0x000f,0x0000,0x0000,
0x000f, 0x000f, 0x0000, 0x0000, 0x000f,0x000f,0x0000,0x0000,
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1327_2bit_96x96_prepare_page_seq[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x015, /* column address... */
XOFFSET, /* start at column 8, special for the LY120 ??? */
0x037, /* end at column 55, note: there are two pixel in one column */
0x075, /* row address... */
U8G_ESC_END /* end of sequence */
};
static void u8g_dev_ssd1327_2bit_prepare_page(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t page = ((u8g_pb_t *)(dev->dev_mem))->p.page;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1327_2bit_96x96_prepare_page_seq);
page <<= 2;
u8g_WriteByte(u8g, dev, page); /* start at the selected page */
page += 3;
u8g_WriteByte(u8g, dev, page); /* end within the selected page */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
static void u8g_dev_ssd1327_2bit_2x_prepare_page(u8g_t *u8g, u8g_dev_t *dev, uint8_t is_odd)
{
uint8_t page = ((u8g_pb_t *)(dev->dev_mem))->p.page;
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1327_2bit_96x96_prepare_page_seq);
page <<= 1;
page += is_odd;
page <<= 2;
u8g_WriteByte(u8g, dev, page); /* start at the selected page */
page += 3;
u8g_WriteByte(u8g, dev, page); /* end within the selected page */
u8g_SetAddress(u8g, dev, 1); /* data mode */
}
/* assumes row autoincrement and activated nibble remap */
static void u8g_dev_ssd1327_2bit_write_4_pixel(u8g_t *u8g, u8g_dev_t *dev, uint8_t left, uint8_t right)
{
uint8_t d, tmp, cnt;
static uint8_t buf[4];
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
cnt = 0;
do
{
if ( left == 0 && right == 0 )
break;
d = left;
d &= 3;
d <<= 4;
tmp = right;
tmp &= 3;
d |= tmp;
d <<= 2;
buf[cnt] = d;
left >>= 2;
right >>= 2;
cnt++;
}while ( cnt < 4 );
u8g_WriteSequence(u8g, dev, 4, buf);
}
static void u8g_dev_ssd1327_2bit_write_buffer(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t cnt, left, right;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
cnt = pb->width;
cnt >>= 1;
ptr = pb->buf;
do
{
left = *ptr++;
right = *ptr++;
u8g_dev_ssd1327_2bit_write_4_pixel(u8g, dev, left, right);
cnt--;
} while( cnt > 0 );
}
static void u8g_dev_ssd1327_2bit_2x_write_buffer(u8g_t *u8g, u8g_dev_t *dev, uint8_t is_odd)
{
uint8_t cnt, left, right;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
ptr = pb->buf;
cnt = pb->width;
if ( is_odd )
ptr += cnt;
cnt >>= 1;
do
{
left = *ptr++;
right = *ptr++;
u8g_dev_ssd1327_2bit_write_4_pixel(u8g, dev, left, right);
cnt--;
} while( cnt > 0 );
}
uint8_t u8g_dev_ssd1327_96x96_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1327_2bit_96x96_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_dev_ssd1327_2bit_prepare_page(u8g, dev);
u8g_dev_ssd1327_2bit_write_buffer(u8g, dev);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
}
return u8g_dev_pb8v2_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1327_96x96_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1327_2bit_96x96_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_dev_ssd1327_2bit_2x_prepare_page(u8g, dev, 0);
u8g_dev_ssd1327_2bit_2x_write_buffer(u8g, dev, 0);
u8g_dev_ssd1327_2bit_2x_prepare_page(u8g, dev, 1);
u8g_dev_ssd1327_2bit_2x_write_buffer(u8g, dev, 1);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
}
return u8g_dev_pb16v2_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_ssd1327_96x96_gr_sw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1327_96x96_gr_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1327_96x96_gr_hw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1327_96x96_gr_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1327_96x96_gr_i2c , WIDTH, HEIGHT, 4, u8g_dev_ssd1327_96x96_gr_fn, U8G_COM_SSD_I2C);
#define DWIDTH (2*WIDTH)
uint8_t u8g_dev_ssd1327_96x96_2x_buf[DWIDTH] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1327_96x96_2x_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1327_96x96_2x_buf};
u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_sw_spi = { u8g_dev_ssd1327_96x96_2x_gr_fn, &u8g_dev_ssd1327_96x96_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_hw_spi = { u8g_dev_ssd1327_96x96_2x_gr_fn, &u8g_dev_ssd1327_96x96_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_i2c = { u8g_dev_ssd1327_96x96_2x_gr_fn, &u8g_dev_ssd1327_96x96_2x_pb, U8G_COM_SSD_I2C };

@ -0,0 +1,787 @@
/*
u8g_dev_ssd1351_128x128.c
Universal 8bit Graphics Library
Copyright (c) 2013, jamjardavies@gmail.com
Copyright (c) 2013, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
History:
Initial version 20 May 2013 jamjardavies@gmail.com
indexed device 22 May 2013 olikraus@gmail.com
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 128
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_ssd1351_128x128_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_DLY(50),
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50),
0xfd, /* Command Lock */
U8G_ESC_ADR(1),
0x12,
U8G_ESC_ADR(0), /* instruction mode */
0xfd,
U8G_ESC_ADR(1),
0xb1, /* Command Lock */
U8G_ESC_ADR(0), /* instruction mode */
0xae, /* Set Display Off */
U8G_ESC_ADR(0), /* instruction mode */
0xb3,
U8G_ESC_ADR(1),
0xf1, /* Front Clock Div */
U8G_ESC_ADR(0), /* instruction mode */
0xca,
U8G_ESC_ADR(1),
0x7f, /* Set Multiplex Ratio */
U8G_ESC_ADR(0), /* instruction mode */
0xa0,
U8G_ESC_ADR(1),
0xb4, /* Set Colour Depth */
U8G_ESC_ADR(0), /* instruction mode */
0x15,
U8G_ESC_ADR(1),
0x00, 0x7f, /* Set Column Address */
U8G_ESC_ADR(0), /* instruction mode */
0x75,
U8G_ESC_ADR(1),
0x00, 0x7f, /* Set Row Address */
U8G_ESC_ADR(0), /* instruction mode */
0xa1,
U8G_ESC_ADR(1),
0x00, /* Set Display Start Line */
U8G_ESC_ADR(0), /* instruction mode */
0xa2,
U8G_ESC_ADR(1),
0x00, /* Set Display Offset */
U8G_ESC_ADR(0), /* instruction mode */
0xb5,
U8G_ESC_ADR(1),
0x00, /* Set GPIO */
U8G_ESC_ADR(0), /* instruction mode */
0xab,
U8G_ESC_ADR(1),
0x01, /* Set Function Selection */
U8G_ESC_ADR(0), /* instruction mode */
0xb1,
U8G_ESC_ADR(1),
0x32, /* Set Phase Length */
U8G_ESC_ADR(0), /* instruction mode */
0xb4,
U8G_ESC_ADR(1),
0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
U8G_ESC_ADR(0), /* instruction mode */
0xbb,
U8G_ESC_ADR(1),
0x17, /* Set Precharge Voltage */
U8G_ESC_ADR(0), /* instruction mode */
0xbe,
U8G_ESC_ADR(1),
0x05, /* Set VComH Voltage */
U8G_ESC_ADR(0), /* instruction mode */
0xc1,
U8G_ESC_ADR(1),
0xc8, 0x80, 0xc8, /* Set Contrast */
U8G_ESC_ADR(0), /* instruction mode */
0xc7,
U8G_ESC_ADR(1),
0x0f, /* Set Master Contrast */
U8G_ESC_ADR(0), /* instruction mode */
0xb6,
U8G_ESC_ADR(1),
0x01, /* Set Second Precharge Period */
U8G_ESC_ADR(0), /* instruction mode */
0xa6, /* Set Display Mode Reset */
U8G_ESC_ADR(0), /* instruction mode */
0xb8, /* Set CMD Grayscale Lookup */
U8G_ESC_ADR(1),
0x05,
0x06,
0x07,
0x08,
0x09,
0x0a,
0x0b,
0x0c,
0x0D,
0x0E,
0x0F,
0x10,
0x11,
0x12,
0x13,
0x14,
0x15,
0x16,
0x18,
0x1a,
0x1b,
0x1C,
0x1D,
0x1F,
0x21,
0x23,
0x25,
0x27,
0x2A,
0x2D,
0x30,
0x33,
0x36,
0x39,
0x3C,
0x3F,
0x42,
0x45,
0x48,
0x4C,
0x50,
0x54,
0x58,
0x5C,
0x60,
0x64,
0x68,
0x6C,
0x70,
0x74,
0x78,
0x7D,
0x82,
0x87,
0x8C,
0x91,
0x96,
0x9B,
0xA0,
0xA5,
0xAA,
0xAF,
0xB4,
U8G_ESC_ADR(0),
0xaf, /* Set Display On */
0x5c,
U8G_ESC_DLY(50),
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1),
U8G_ESC_END /* end of sequence */
};
/* set gpio to high */
static const uint8_t u8g_dev_ssd1351_128x128gh_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_DLY(50),
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50),
0xfd, /* Command Lock */
U8G_ESC_ADR(1),
0x12,
U8G_ESC_ADR(0), /* instruction mode */
0xfd,
U8G_ESC_ADR(1),
0xb1, /* Command Lock */
U8G_ESC_ADR(0), /* instruction mode */
0xae, /* Set Display Off */
U8G_ESC_ADR(0), /* instruction mode */
0xb3,
U8G_ESC_ADR(1),
0xf1, /* Front Clock Div */
U8G_ESC_ADR(0), /* instruction mode */
0xca,
U8G_ESC_ADR(1),
0x7f, /* Set Multiplex Ratio */
U8G_ESC_ADR(0), /* instruction mode */
0xa0,
U8G_ESC_ADR(1),
0xb4, /* Set Colour Depth */
U8G_ESC_ADR(0), /* instruction mode */
0x15,
U8G_ESC_ADR(1),
0x00, 0x7f, /* Set Column Address */
U8G_ESC_ADR(0), /* instruction mode */
0x75,
U8G_ESC_ADR(1),
0x00, 0x7f, /* Set Row Address */
U8G_ESC_ADR(0), /* instruction mode */
0xa1,
U8G_ESC_ADR(1),
0x00, /* Set Display Start Line */
U8G_ESC_ADR(0), /* instruction mode */
0xa2,
U8G_ESC_ADR(1),
0x00, /* Set Display Offset */
U8G_ESC_ADR(0), /* instruction mode */
0xb5,
U8G_ESC_ADR(1),
0x03, /* Set GPIO to High Level */
U8G_ESC_ADR(0), /* instruction mode */
0xab,
U8G_ESC_ADR(1),
0x01, /* Set Function Selection */
U8G_ESC_ADR(0), /* instruction mode */
0xb1,
U8G_ESC_ADR(1),
0x32, /* Set Phase Length */
U8G_ESC_ADR(0), /* instruction mode */
0xb4,
U8G_ESC_ADR(1),
0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
U8G_ESC_ADR(0), /* instruction mode */
0xbb,
U8G_ESC_ADR(1),
0x17, /* Set Precharge Voltage */
U8G_ESC_ADR(0), /* instruction mode */
0xbe,
U8G_ESC_ADR(1),
0x05, /* Set VComH Voltage */
U8G_ESC_ADR(0), /* instruction mode */
0xc1,
U8G_ESC_ADR(1),
0xc8, 0x80, 0xc8, /* Set Contrast */
U8G_ESC_ADR(0), /* instruction mode */
0xc7,
U8G_ESC_ADR(1),
0x0f, /* Set Master Contrast */
U8G_ESC_ADR(0), /* instruction mode */
0xb6,
U8G_ESC_ADR(1),
0x01, /* Set Second Precharge Period */
U8G_ESC_ADR(0), /* instruction mode */
0xa6, /* Set Display Mode Reset */
U8G_ESC_ADR(0), /* instruction mode */
0xb8, /* Set CMD Grayscale Lookup */
U8G_ESC_ADR(1),
0x05,
0x06,
0x07,
0x08,
0x09,
0x0a,
0x0b,
0x0c,
0x0D,
0x0E,
0x0F,
0x10,
0x11,
0x12,
0x13,
0x14,
0x15,
0x16,
0x18,
0x1a,
0x1b,
0x1C,
0x1D,
0x1F,
0x21,
0x23,
0x25,
0x27,
0x2A,
0x2D,
0x30,
0x33,
0x36,
0x39,
0x3C,
0x3F,
0x42,
0x45,
0x48,
0x4C,
0x50,
0x54,
0x58,
0x5C,
0x60,
0x64,
0x68,
0x6C,
0x70,
0x74,
0x78,
0x7D,
0x82,
0x87,
0x8C,
0x91,
0x96,
0x9B,
0xA0,
0xA5,
0xAA,
0xAF,
0xB4,
U8G_ESC_ADR(0),
0xaf, /* Set Display On */
0x5c,
U8G_ESC_DLY(50),
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1),
U8G_ESC_END /* end of sequence */
};
#define u8g_dev_ssd1351_128x128_init_seq u8g_dev_ssd1351_128x128_init_seq
static const uint8_t u8g_dev_ssd1351_128x128_column_seq[] PROGMEM = {
U8G_ESC_CS(1),
U8G_ESC_ADR(0), 0x15,
U8G_ESC_ADR(1), 0x00, 0x7f,
U8G_ESC_ADR(0), 0x75,
U8G_ESC_ADR(1), 0x00, 0x7f,
U8G_ESC_ADR(0), 0x5c,
U8G_ESC_ADR(1),
U8G_ESC_CS(0),
U8G_ESC_END
};
#define RGB332_STREAM_BYTES 8
static uint8_t u8g_ssd1351_stream_bytes[RGB332_STREAM_BYTES*3];
void u8g_ssd1351_to_stream(uint8_t *ptr)
{
uint8_t cnt = RGB332_STREAM_BYTES;
uint8_t val;
uint8_t *dest = u8g_ssd1351_stream_bytes;
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
{
val = *ptr++;
*dest++ = ((val & 0xe0) >> 2);
*dest++ = ((val & 0x1c) << 1);
*dest++ = ((val & 0x03) << 4);
}
}
#ifdef OBSOLETE
// Convert the internal RGB 332 to R
static uint8_t u8g_ssd1351_get_r(uint8_t colour)
{
//return ((colour & 0xe0) >> 5) * 9;
//return ((colour & 0xe0) >> 5) * 8;
return ((colour & 0xe0) >> 2) ;
}
// Convert the internal RGB 332 to G
static uint8_t u8g_ssd1351_get_g(uint8_t colour)
{
//return ((colour & 0x1c) >> 2) * 9;
//return ((colour & 0x1c) >> 2) * 8;
return ((colour & 0x1c) << 1);
}
// Convert the internal RGB 332 to B
static uint8_t u8g_ssd1351_get_b(uint8_t colour)
{
//return (colour & 0x03) * 21;
return (colour & 0x03) * 16;
}
#endif
uint8_t u8g_dev_ssd1351_128x128_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_uint_t x;
uint8_t page_height;
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( i = 0; i < page_height; i++ )
{
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
{
u8g_ssd1351_to_stream(ptr);
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
ptr += RGB332_STREAM_BYTES;
}
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_R3G3B2;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1351_128x128gh_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_uint_t x;
uint8_t page_height;
uint8_t i;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( i = 0; i < page_height; i++ )
{
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
{
u8g_ssd1351_to_stream(ptr);
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
ptr += RGB332_STREAM_BYTES;
}
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_R3G3B2;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
static uint8_t u8g_dev_ssd1351_128x128_r[256];
static uint8_t u8g_dev_ssd1351_128x128_g[256];
static uint8_t u8g_dev_ssd1351_128x128_b[256];
uint8_t u8g_dev_ssd1351_128x128_idx_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
u8g_dev_ssd1351_128x128_r[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->r;
u8g_dev_ssd1351_128x128_g[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->g;
u8g_dev_ssd1351_128x128_b[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->b;
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
int x;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
for (x = 0; x < pb->width; x++)
{
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_r[(*ptr)>>2]);
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_g[(*ptr)>>2]);
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_b[(*ptr)>>2]);
ptr++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_INDEX;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
void u8g_ssd1351_hicolor_to_stream(uint8_t *ptr)
{
register uint8_t cnt = RGB332_STREAM_BYTES;
register uint8_t low, high, r, g, b;
uint8_t *dest = u8g_ssd1351_stream_bytes;
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
{
low = *ptr++;
high = *ptr++;
r = high & ~7;
r >>= 2;
b = low & 31;
b <<= 1;
g = high & 7;
g <<= 3;
g |= (low>>5)&7;
*dest++ = r;
*dest++ = g;
*dest++ = b;
}
}
uint8_t u8g_dev_ssd1351_128x128_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t i, j;
uint8_t page_height;
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( j = 0; j < page_height; j++ )
{
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
{
u8g_ssd1351_hicolor_to_stream(ptr);
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
ptr += RGB332_STREAM_BYTES*2;
}
}
u8g_SetChipSelect(u8g, dev, 0);
}
break; /* continue to base fn */
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_HICOLOR;
}
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1351_128x128gh_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t i, j;
uint8_t page_height;
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( j = 0; j < page_height; j++ )
{
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
{
u8g_ssd1351_hicolor_to_stream(ptr);
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
ptr += RGB332_STREAM_BYTES*2;
}
}
u8g_SetChipSelect(u8g, dev, 0);
}
break; /* continue to base fn */
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_HICOLOR;
}
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1351_128x128_byte_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1351_128x128_byte_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
u8g_dev_t u8g_dev_ssd1351_128x128_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
//u8g_dev_t u8g_dev_ssd1351_128x128_idx_sw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
//u8g_dev_t u8g_dev_ssd1351_128x128_idx_hw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
/* only half of the height, because two bytes are needed for one pixel */
u8g_pb_t u8g_dev_ssd1351_128x128_hicolor_byte_pb = { {PAGE_HEIGHT/2, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
uint8_t u8g_dev_ssd1351_128x128_4x_byte_buf[WIDTH*PAGE_HEIGHT*4] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1351_128x128_4x_332_byte_pb = { {PAGE_HEIGHT*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
u8g_pb_t u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb = { {PAGE_HEIGHT/2*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
/*
U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_HW_SPI);
*/

@ -0,0 +1,425 @@
/*
u8g_dev_ssd1353_160x128.c
Universal 8bit Graphics Library
Copyright (c) 2015, hugodan3@googlemail.com
Copyright (c) 2013, jamjardavies@gmail.com
Copyright (c) 2013, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
History:
Initial version 8 Mar 2015 hugodan3@googlemail.com. This version has
been derived from the ssd1351 driver by jamjarda. It has
been improved by in-lining time critical functions.
*/
#include "u8g.h"
#define WIDTH 160
#define HEIGHT 128
#define PAGE_HEIGHT 8
#define USE_GREY_TABLE 0
static const uint8_t u8g_dev_ssd1353_160x128_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_DLY(50),
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_DLY(50),
U8G_ESC_CS(1), /* enable chip */
0xFD, /* Command unlock */
U8G_ESC_ADR(1),
0x12,
U8G_ESC_ADR(0),
0xAE, /* Set Display Off */
U8G_ESC_ADR(0),
0xA8,
U8G_ESC_ADR(1),
0x7F, /* Set Multiplex Ratio */
U8G_ESC_ADR(0),
0xA0,
U8G_ESC_ADR(1),
0xB4, /* Set remapping */
U8G_ESC_ADR(0),
0xA1,
U8G_ESC_ADR(1),
0x00, /* Set Display Start Line */
U8G_ESC_ADR(0),
0xA2,
U8G_ESC_ADR(1),
0x00, /* Set Display Offset */
U8G_ESC_ADR(0),
0xB1,
U8G_ESC_ADR(1),
0x32, /* Set Phase Length */
U8G_ESC_ADR(0),
0xB4,
U8G_ESC_ADR(1),
0x04, /* Set Second Precharge Period */
U8G_ESC_ADR(0),
0xA4, /* Set Display Mode ON */
U8G_ESC_ADR(0),
0xB3,
U8G_ESC_ADR(1), /* frame rate */
0x40,
U8G_ESC_ADR(0),
0xBB,
U8G_ESC_ADR(1), /* pre-charge level */
0x08,
U8G_ESC_ADR(0),
0xBE,
U8G_ESC_ADR(1), /* vcomh */
0x3C,
/* color adjustments */
#if USE_GREY_TABLE != 1
U8G_ESC_ADR(0), /* instruction mode */
0x81,
U8G_ESC_ADR(1),
0xC8, /* Set Contrast Color 1*/
U8G_ESC_ADR(0), /* instruction mode */
0x82,
U8G_ESC_ADR(1),
0x80, /* Set Contrast Color 2*/
U8G_ESC_ADR(0), /* instruction mode */
0x83,
U8G_ESC_ADR(1),
0xF8, /* Set Contrast Color 3*/
U8G_ESC_ADR(0), /* instruction mode */
0x87,
U8G_ESC_ADR(1),
0x09, /* Set Master Contrast MAX */
U8G_ESC_ADR(0), /* instruction mode */
0xB9, /* Set CMD Grayscale Linear */
#else
U8G_ESC_ADR(0), /* instruction mode */
0x81,
U8G_ESC_ADR(1),
0xC8, /* Set Contrast Color 1*/
U8G_ESC_ADR(0), /* instruction mode */
0x82,
U8G_ESC_ADR(1),
0xA0, /* Set Contrast Color 2*/
U8G_ESC_ADR(0), /* instruction mode */
0x83,
U8G_ESC_ADR(1),
0xB0, /* Set Contrast Color 3*/
U8G_ESC_ADR(0), /* instruction mode */
0x87,
U8G_ESC_ADR(1),
0x0F, /* Set Master Contrast MAX */
U8G_ESC_ADR(0), /* instruction mode */
0xB8, /* Set CMD Grayscale Lookup */
U8G_ESC_ADR(1),
0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c,
0x0D, 0x0E, 0x0F, 0x10,
0x11, 0x12, 0x13, 0x14,
0x15, 0x16, 0x18, 0x1a,
0x1b, 0x1C, 0x1D, 0x1F,
0x21, 0x23, 0x25, 0x27,
0x2A, 0x2D, 0x30, 0x33,
0x36, 0x39, 0x3C, 0x3F,
0x42, 0x45, 0x48, 0x4C,
0x50, 0x54, 0x58, 0x5C,
0x60, 0x64, 0x68, 0x6C,
0x70, 0x74, 0x78, 0x7D,
0x82, 0x87, 0x8C, 0x91,
0x96, 0x9B, 0xA0, 0xA5,
0xAA, 0xAF, 0xB4,
#endif
U8G_ESC_ADR(0),
0xAF, /* Set Display On */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(1),
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_ssd1353_160x128_column_seq[] PROGMEM = {
U8G_ESC_CS(1),
U8G_ESC_ADR(0), 0x15,
U8G_ESC_ADR(1), 0x00, 0x9f,
U8G_ESC_ADR(0), 0x75,
U8G_ESC_ADR(1), 0x00, 0x7f,
U8G_ESC_ADR(0), 0x5c,
U8G_ESC_ADR(1),
U8G_ESC_CS(0),
U8G_ESC_END
};
static const uint8_t u8g_dev_ssd1353_160x128_sleep_on[] PROGMEM = {
U8G_ESC_CS(1),
U8G_ESC_ADR(0), 0xAE,
U8G_ESC_CS(0),
U8G_ESC_END
};
static const uint8_t u8g_dev_ssd1353_160x128_sleep_off[] PROGMEM = {
U8G_ESC_CS(1),
U8G_ESC_ADR(0), 0xAF,
U8G_ESC_CS(0),
U8G_ESC_END
};
#define RGB332_STREAM_BYTES 8
static uint8_t u8g_ssd1353_stream_bytes[RGB332_STREAM_BYTES*3];
uint8_t u8g_dev_ssd1353_160x128_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_uint_t x;
uint8_t page_height;
uint8_t i;
uint8_t cnt;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( i = 0; i < page_height; i++ )
{
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
{
/* inline operation for better perf */
uint8_t *dest = u8g_ssd1353_stream_bytes;
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
{
uint8_t val = *ptr++;
*dest++ = ((val & 0xe0) >> 2);
*dest++ = ((val & 0x1c) << 1);
*dest++ = ((val & 0x03) << 4);
}
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1353_stream_bytes);
}
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_sleep_on);
break;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_sleep_off);
break;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
/*
* not tested and not released, just taken from ssd1351
*/
static uint8_t u8g_dev_ssd1353_160x128_r[256];
static uint8_t u8g_dev_ssd1353_160x128_g[256];
static uint8_t u8g_dev_ssd1353_160x128_b[256];
uint8_t u8g_dev_ssd1353_160x128_idx_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
u8g_dev_ssd1353_160x128_r[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->r;
u8g_dev_ssd1353_160x128_g[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->g;
u8g_dev_ssd1353_160x128_b[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->b;
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
int x;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
for (x = 0; x < pb->width; x++)
{
u8g_WriteByte(u8g, dev, u8g_dev_ssd1353_160x128_r[(*ptr)>>2]);
u8g_WriteByte(u8g, dev, u8g_dev_ssd1353_160x128_g[(*ptr)>>2]);
u8g_WriteByte(u8g, dev, u8g_dev_ssd1353_160x128_b[(*ptr)>>2]);
ptr++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_INDEX;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1353_160x128_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_column_seq);
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
uint8_t i, j;
uint8_t page_height;
uint8_t *ptr = pb->buf;
u8g_SetChipSelect(u8g, dev, 1);
page_height = pb->p.page_y1;
page_height -= pb->p.page_y0;
page_height++;
for( j = 0; j < page_height; j++ )
{
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
{
register uint8_t cnt, low, high, r, g, b;
uint8_t *dest = u8g_ssd1353_stream_bytes;
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
{
low = *ptr++;
high = *ptr++;
r = high & ~7;
r >>= 2;
b = low & 31;
b <<= 1;
g = high & 7;
g <<= 3;
g |= (low>>5)&7;
*dest++ = r;
*dest++ = g;
*dest++ = b;
}
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1353_stream_bytes);
}
}
u8g_SetChipSelect(u8g, dev, 0);
}
break; /* continue to base fn */
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_sleep_on);
break;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1353_160x128_sleep_off);
break;
}
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_ssd1353_160x128_byte_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1353_160x128_byte_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1353_160x128_byte_buf};
u8g_dev_t u8g_dev_ssd1353_160x128_332_sw_spi = { u8g_dev_ssd1353_160x128_332_fn, &u8g_dev_ssd1353_160x128_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1353_160x128_332_hw_spi = { u8g_dev_ssd1353_160x128_332_fn, &u8g_dev_ssd1353_160x128_byte_pb, U8G_COM_HW_SPI };
//u8g_dev_t u8g_dev_ssd1353_160x128_idx_sw_spi = { u8g_dev_ssd1353_160x128_idx_fn, &u8g_dev_ssd1353_160x128_byte_pb, U8G_COM_SW_SPI };
//u8g_dev_t u8g_dev_ssd1353_160x128_idx_hw_spi = { u8g_dev_ssd1353_160x128_idx_fn, &u8g_dev_ssd1353_160x128_byte_pb, U8G_COM_HW_SPI };
/* only half of the height, because two bytes are needed for one pixel */
u8g_pb_t u8g_dev_ssd1353_160x128_hicolor_byte_pb = { {PAGE_HEIGHT/2, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1353_160x128_byte_buf};
u8g_dev_t u8g_dev_ssd1353_160x128_hicolor_sw_spi = { u8g_dev_ssd1353_160x128_hicolor_fn, &u8g_dev_ssd1353_160x128_hicolor_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1353_160x128_hicolor_hw_spi = { u8g_dev_ssd1353_160x128_hicolor_fn, &u8g_dev_ssd1353_160x128_hicolor_byte_pb, U8G_COM_HW_SPI };
/* the 4x buffer is removed since it does not fit the RAM space of very small MCUs */
#if 0
uint8_t u8g_dev_ssd1353_160x128_4x_byte_buf[WIDTH*PAGE_HEIGHT*4] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_ssd1353_160x128_4x_332_byte_pb = { {PAGE_HEIGHT*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1353_160x128_4x_byte_buf};
u8g_dev_t u8g_dev_ssd1353_160x128_4x_332_sw_spi = { u8g_dev_ssd1353_160x128_332_fn, &u8g_dev_ssd1353_160x128_4x_332_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1353_160x128_4x_332_hw_spi = { u8g_dev_ssd1353_160x128_332_fn, &u8g_dev_ssd1353_160x128_4x_332_byte_pb, U8G_COM_HW_SPI };
u8g_pb_t u8g_dev_ssd1353_160x128_4x_hicolor_byte_pb = { {PAGE_HEIGHT/2*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1353_160x128_4x_byte_buf};
u8g_dev_t u8g_dev_ssd1353_160x128_4x_hicolor_sw_spi = { u8g_dev_ssd1353_160x128_hicolor_fn, &u8g_dev_ssd1353_160x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_ssd1353_160x128_4x_hicolor_hw_spi = { u8g_dev_ssd1353_160x128_hicolor_fn, &u8g_dev_ssd1353_160x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
#endif

@ -0,0 +1,203 @@
/*
u8g_dev_st7565_64128n.c (Displaytech)
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
static const uint8_t u8g_dev_st7565_64128n_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
0x0A2, /* 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
0x0A0, /* Normal ADC Select (according to Displaytech 64128N datasheet) */
0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
0x040, /* Display start line for Displaytech 64128N */
0x028 | 0x04, /* power control: turn on voltage converter */
U8G_ESC_DLY(50), /* delay 50 ms */
0x028 | 0x06, /* power control: turn on voltage regulator */
U8G_ESC_DLY(50), /* delay 50 ms */
0x028 | 0x07, /* power control: turn on voltage follower */
U8G_ESC_DLY(50), /* delay 50 ms */
0x010, /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x081, /* set contrast */
0x01e, /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_64128n_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0x10 */
0x000, /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_64128n_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_64128n_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_64128n_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7565_64128n_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_64128n_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_64128n_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_st7565_64128n_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_PARALLEL);
uint8_t u8g_dev_st7565_64128n_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7565_64128n_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_64128n_2x_buf};
u8g_dev_t u8g_dev_st7565_64128n_2x_sw_spi = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_st7565_64128n_2x_hw_spi = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_st7565_64128n_2x_hw_parallel = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_PARALLEL };

@ -0,0 +1,190 @@
/*
u8g_dev_st7565_dogm128.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
const uint8_t u8g_dev_st7565_dogm128_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x040, /* set display start line */
0x0a1, /* ADC set to reverse */
0x0c0, /* common output mode: set scan direction normal operation */
0x0a6, /* display normal (none reverse) */
0x0a2, /* LCD bias 1/9 */
0x02f, /* all power control circuits on */
0x0f8, /* set booster ratio to */
0x000, /* 4x */
0x027, /* set V0 voltage resistor ratio to large */
0x081, /* set contrast */
0x018, /* contrast value, EA default: 0x016 */
0x0ac, /* indicator */
0x000, /* disable */
0x0a4, /* normal display (not all on) */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_dogm128_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x000, /* set lower 4 bit of the col adr to 0 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_dogm128_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_dogm128_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_dogm128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7565_dogm128_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_dogm128_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm128_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_dogm128_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm128_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_st7565_dogm128_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm128_fn, U8G_COM_PARALLEL);
uint8_t u8g_dev_st7565_dogm128_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7565_dogm128_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_dogm128_2x_buf};
u8g_dev_t u8g_dev_st7565_dogm128_2x_sw_spi = { u8g_dev_st7565_dogm128_2x_fn, &u8g_dev_st7565_dogm128_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_st7565_dogm128_2x_hw_spi = { u8g_dev_st7565_dogm128_2x_fn, &u8g_dev_st7565_dogm128_2x_pb, U8G_COM_HW_SPI };
u8g_dev_t u8g_dev_st7565_dogm128_2x_parallel = { u8g_dev_st7565_dogm128_2x_fn, &u8g_dev_st7565_dogm128_2x_pb, U8G_COM_PARALLEL };

@ -0,0 +1,157 @@
/*
u8g_dev_st7565_dogm132.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 132
#define HEIGHT 32
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_st7565_dogm132_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x040, /* set display start line to 0 */
0x0a1, /* ADC set to reverse */
0x0c0, /* common output mode */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x0a2, /* LCD bias 1/9 */
0x02f, /* all power control circuits on */
0x0f8, /* set booster ratio to */
0x000, /* 4x */
0x023, /* set V0 voltage resistor ratio to large */
0x081, /* set contrast */
0x01f, /* contrast value, EA default: 0x01f */
0x0ac, /* indicator */
0x000, /* disable */
0x0af, /* display on */
#ifdef OBSOLETE_DOGM128
0x040, /* set display start line */
0x0c8, /* set scan direction inverse operation */
0x0a2, /* LCD bias 1/9 */
0x02f, /* all power control circuits on */
0x0f8, /* set booster ratio to */
0x000, /* 4x */
0x027, /* set V0 voltage resistor ratio to large */
0x081, /* set contrast */
0x018, /* contrast value, EA default: 0x016 */
0x0ac, /* indicator */
0x000, /* disable */
0x0af, /* display on */
#endif
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_dogm132_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x000, /* set lower 4 bit of the col adr to 0 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_dogm132_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_dogm132_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_dogm132_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm132_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm132_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm132_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm132_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_dogm132_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm132_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_dogm132_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm132_fn, U8G_COM_HW_SPI);

@ -0,0 +1,205 @@
/*
u8g_dev_st7565_lm6059.c (Adafruit display)
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
static const uint8_t u8g_dev_st7565_lm6059_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
0x0a3, /* 0x0a2: LCD bias 1/9 (suggested for the LM6063), 0x0a3: Used by Adafruit, 0x0a2 does not work */
/* the LM6059 vs LM6063, ADC and SHL have inverted settings */
0x0a0, /* 0x0a1: ADC set to normal (suggested for the LM6059), 0x0a0: Used by Adafruit -> normal mode */
0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
0x060, /* set display start line */
0x028 | 0x04, /* power control: turn on voltage converter */
U8G_ESC_DLY(50), /* delay 50 ms */
0x028 | 0x06, /* power control: turn on voltage regulator */
U8G_ESC_DLY(50), /* delay 50 ms */
0x028 | 0x07, /* power control: turn on voltage follower */
U8G_ESC_DLY(50), /* delay 50 ms */
0x026, /* set V0 voltage resistor ratio to 6 (Adafruit Value, no info from LM6063 Manual) */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x081, /* set contrast */
0x018, /* contrast value*/
/*0x0ac,*/ /* indicator */
/*0x000,*/ /* disable */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_lm6059_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x001, /* set lower 4 bit of the col adr */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_lm6059_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_lm6059_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_lm6059_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7565_lm6059_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_lm6059_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6059_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_lm6059_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6059_fn, U8G_COM_HW_SPI);
uint8_t u8g_dev_st7565_lm6059_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7565_lm6059_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_lm6059_2x_buf};
u8g_dev_t u8g_dev_st7565_lm6059_2x_sw_spi = { u8g_dev_st7565_lm6059_2x_fn, &u8g_dev_st7565_lm6059_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_st7565_lm6059_2x_hw_spi = { u8g_dev_st7565_lm6059_2x_fn, &u8g_dev_st7565_lm6059_2x_pb, U8G_COM_HW_SPI };

@ -0,0 +1,236 @@
/*
u8g_dev_st7565_lm6063.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
#ifdef OLD_ADAFRUIT_CODE
static const uint8_t OLD_u8g_dev_st7565_lm6063_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x040, /* set display start line */
0x0a1, /* ADC set to reverse */
0x0c8, /* common output mode: set scan direction normal operation/SHL Select / 17 Jan: seems to be a bug, must be 0x0c0 */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x0a2, /* LCD bias 1/9 */
0x02f, /* all power control circuits on */
/*0x0f8,*/ /* set booster ratio to */
/*0x000, */ /* 4x */
/*0x027,*/ /* set V0 voltage resistor ratio to large */
0x081, /* set contrast */
0x018, /* contrast value*/
0x0ac, /* indicator */
0x000, /* disable */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
#endif
/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
static const uint8_t u8g_dev_st7565_lm6063_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
0x0a3, /* 0x0a2: LCD bias 1/9 (suggested for the LM6063), 0x0a3: Used by Adafruit */
0x0a1, /* 0x0a1: ADC set to reverse (suggested for the LM6063), 0x0a0: Used by Adafruit -> normal mode */
0x0c0, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
0x040, /* set display start line */
0x028 | 0x04, /* power control: turn on voltage converter */
U8G_ESC_DLY(50), /* delay 50 ms */
0x028 | 0x06, /* power control: turn on voltage regulator */
U8G_ESC_DLY(50), /* delay 50 ms */
0x028 | 0x07, /* power control: turn on voltage follower */
U8G_ESC_DLY(50), /* delay 50 ms */
0x026, /* set V0 voltage resistor ratio to 6 (Adafruit Value, no info from LM6063 Manual) */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x081, /* set contrast */
0x018, /* contrast value*/
/*0x0ac,*/ /* indicator */
/*0x000,*/ /* disable */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_lm6063_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x000, /* set lower 4 bit of the col adr to 0 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_st7565_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_st7565_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_lm6063_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7565_lm6063_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_lm6063_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6063_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_lm6063_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6063_fn, U8G_COM_HW_SPI);
uint8_t u8g_dev_st7565_lm6063_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7565_lm6063_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_lm6063_2x_buf};
u8g_dev_t u8g_dev_st7565_lm6063_2x_sw_spi = { u8g_dev_st7565_lm6063_2x_fn, &u8g_dev_st7565_lm6063_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_st7565_lm6063_2x_hw_spi = { u8g_dev_st7565_lm6063_2x_fn, &u8g_dev_st7565_lm6063_2x_pb, U8G_COM_HW_SPI };

@ -0,0 +1,145 @@
/*
u8g_dev_st7565_nhd_c12832.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 32
#define PAGE_HEIGHT 8
static const uint8_t u8g_dev_st7565_c12832_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x040, /* set display start line to 0 */
0x0a0, /* ADC set, values: a0=normal, a1=reverse */
0x0c8, /* common output mode: c0=normal, c8=reverse */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x0a2, /* LCD bias 1/9 */
0x02f, /* all power control circuits on */
0x0f8, /* set booster ratio to */
0x000, /* 4x */
0x023, /* set V0 voltage resistor ratio to large */
0x081, /* set contrast */
0x00a, /* contrast value */
0x0ac, /* indicator */
0x000, /* disable */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_c12832_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x000, /* set lower 4 bit of the col adr to 0 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_c12832_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_c12832_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_c12832_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12832_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12832_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12832_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12832_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_HW_SPI);
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_PARALLEL);
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_hw_usart_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_HW_USART_SPI);

@ -0,0 +1,194 @@
/*
u8g_dev_st7565_nhd_c12864.c
Support for the NHD-C12864A1Z-FSB-FBW (Newhaven Display)
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
const uint8_t u8g_dev_st7565_nhd_c12864_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(10), /* do reset low pulse with (10*16)+2 milliseconds */
U8G_ESC_CS(1), /* enable chip */
0x040, /* set display start line */
0x0a1, /* ADC set to reverse */
0x0c0, /* common output mode: set scan direction normal operation */
0x0a6, /* display normal, bit val 0: LCD pixel off. */
0x0a2, /* LCD bias 1/9 */
0x02f, /* all power control circuits on */
0x0f8, /* set booster ratio to */
0x000, /* 4x */
0x027, /* set V0 voltage resistor ratio to large */
0x081, /* set contrast */
0x008, /* contrast: 0x008 is a good value for NHD C12864, Nov 2012: User reports that 0x1a is much better */
0x0ac, /* indicator */
0x000, /* disable */
0x0af, /* display on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a5, /* display all points, ST7565 */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0a4, /* normal display */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_nhd_c12864_data_start[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x010, /* set upper 4 bit of the col adr to 0 */
0x004, /* set lower 4 bit of the col adr to 4 (NHD C12864) */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_c12864_sleep_on[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0ac, /* static indicator off */
0x000, /* indicator register set (not sure if this is required) */
0x0ae, /* display off */
0x0a5, /* all points on */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
static const uint8_t u8g_dev_st7565_c12864_sleep_off[] PROGMEM = {
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
0x0a4, /* all points off */
0x0af, /* display on */
U8G_ESC_DLY(50), /* delay 50 ms */
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7565_nhd_c12864_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
return 0;
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_off);
return 1;
}
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7565_nhd_c12864_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
u8g_SetChipSelect(u8g, dev, 0);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_data_start);
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
u8g_SetChipSelect(u8g, dev, 0);
}
break;
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
u8g_SetChipSelect(u8g, dev, 0);
return 1;
case U8G_DEV_MSG_SLEEP_ON:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_on);
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_off);
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7565_nhd_c12864_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_nhd_c12864_fn, U8G_COM_SW_SPI);
U8G_PB_DEV(u8g_dev_st7565_nhd_c12864_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_nhd_c12864_fn, U8G_COM_HW_SPI);
uint8_t u8g_dev_st7565_nhd_c12864_2x_buf[WIDTH*2] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7565_nhd_c12864_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_nhd_c12864_2x_buf};
u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_sw_spi = { u8g_dev_st7565_nhd_c12864_2x_fn, &u8g_dev_st7565_nhd_c12864_2x_pb, U8G_COM_SW_SPI };
u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_hw_spi = { u8g_dev_st7565_nhd_c12864_2x_fn, &u8g_dev_st7565_nhd_c12864_2x_pb, U8G_COM_HW_SPI };

@ -0,0 +1,420 @@
/*
u8g_dev_st7687_c144mvgd.c (1.44" TFT)
Status: Started, but not finished
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 128
#define PAGE_HEIGHT 8
#ifdef FIRST_VERSION
/*
see also: read.pudn.com/downloads115/sourcecode/app/484503/LCM_Display.c__.htm
http://en.pudn.com/downloads115/sourcecode/app/detail484503_en.html
*/
static const uint8_t u8g_dev_st7687_c144mvgd_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
0x001, /* A0=0, SW reset */
U8G_ESC_DLY(200), /* delay 200 ms */
0x0d7, /* EEPROM data auto re-load control */
U8G_ESC_ADR(1), /* data mode */
0x09f, /* ARD = 1 */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0e0, /* EEPROM control in */
U8G_ESC_ADR(1), /* data mode */
0x000, /* */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_DLY(100), /* delay 100 ms */
#ifdef NOT_REQUIRED
0x0fa, /* EEPROM function selection 8.1.66 */
U8G_ESC_ADR(1), /* data mode */
0x000, /* */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_DLY(100), /* delay 100 ms */
#endif
0x0e3, /* Read from EEPROM, 8.1.55 */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0e1, /* EEPROM control out, 8.1.53 */
U8G_ESC_DLY(100), /* delay 100 ms */
//0x028, /* display off */
0x011, /* Sleep out & booster on */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0c0, /* Vop setting, 8.1.42 */
U8G_ESC_ADR(1), /* data mode */
0x000, /* */
0x001, /* 3.6 + 256*0.04 = 13.84 Volt */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_DLY(100), /* delay 100 ms */
0x0c3, /* Bias selection, 8.1.45 */
U8G_ESC_ADR(1), /* data mode */
0x003,
U8G_ESC_ADR(0), /* instruction mode */
0x0c4, /* Booster setting 8.1.46 */
U8G_ESC_ADR(1), /* data mode */
0x007,
U8G_ESC_ADR(0), /* instruction mode */
0x0c5, /* ??? */
U8G_ESC_ADR(1), /* data mode */
0x001,
U8G_ESC_ADR(0), /* instruction mode */
0x0cb, /* FV3 with Booster x2 control, 8.1.47 */
U8G_ESC_ADR(1), /* data mode */
0x001,
U8G_ESC_ADR(0), /* instruction mode */
0x036, /* Memory data access control, 8.1.28 */
U8G_ESC_ADR(1), /* data mode */
0x080,
U8G_ESC_ADR(0), /* instruction mode */
0x0b5, /* N-line control, 8.1.37 */
U8G_ESC_ADR(1), /* data mode */
0x089,
U8G_ESC_ADR(0), /* instruction mode */
0x0d0, /* Analog circuit setting, 8.1.49 */
U8G_ESC_ADR(1), /* data mode */
0x01d,
U8G_ESC_ADR(0), /* instruction mode */
0x0b7, /* Com/Seg Scan Direction, 8.1.38 */
U8G_ESC_ADR(1), /* data mode */
0x040,
U8G_ESC_ADR(0), /* instruction mode */
0x025, /* Write contrast, 8.1.17 */
U8G_ESC_ADR(1), /* data mode */
0x03f,
U8G_ESC_ADR(0), /* instruction mode */
0x03a, /* Interface pixel format, 8.1.32 */
U8G_ESC_ADR(1), /* data mode */
0x004, /* 3: 12 bit per pixel Type A, 4: 12 bit Type B, 5: 16bit per pixel */
U8G_ESC_ADR(0), /* instruction mode */
0x0b0, /* Display Duty setting, 8.1.34 */
U8G_ESC_ADR(1), /* data mode */
0x07f,
U8G_ESC_ADR(0), /* instruction mode */
0x0f0, /* Frame Freq. in Temp range A,B,C and D, 8.1.59 */
U8G_ESC_ADR(1), /* data mode */
0x007,
0x00c,
0x00c,
0x015,
U8G_ESC_ADR(0), /* instruction mode */
0x0f9, /* Frame RGB Value, 8.1.65 */
U8G_ESC_ADR(1), /* data mode */
0x000,
0x005,
0x008,
0x00a,
0x00c,
0x00e,
0x010,
0x011,
0x012,
0x013,
0x014,
0x015,
0x016,
0x018,
0x01a,
0x01b,
U8G_ESC_ADR(0), /* instruction mode */
0x0f9, /* Frame RGB Value, 8.1.65 */
U8G_ESC_ADR(1), /* data mode */
0x000,
0x000,
0x000,
0x000,
0x033,
0x055,
0x055,
0x055,
U8G_ESC_ADR(0), /* instruction mode */
0x029, /* display on */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
#else
/*
http://www.waitingforfriday.com/images/e/e3/FTM144D01N_test.zip
*/
static const uint8_t u8g_dev_st7687_c144mvgd_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
0x011, /* Sleep out & booster on */
U8G_ESC_DLY(5), /* delay 5 ms */
0x03a, /* Interface pixel format, 8.1.32 */
U8G_ESC_ADR(1), /* data mode */
0x004, /* 3: 12 bit per pixel Type A, 4: 12 bit Type B, 5: 16bit per pixel */
U8G_ESC_ADR(0), /* instruction mode */
0x026, /* SET_GAMMA_CURVE */
U8G_ESC_ADR(1), /* data mode */
0x004,
U8G_ESC_ADR(0), /* instruction mode */
0x0f2, /* GAM_R_SEL */
U8G_ESC_ADR(1), /* data mode */
0x001, /* enable gamma adj */
U8G_ESC_ADR(0), /* instruction mode */
0x0e0, /* POSITIVE_GAMMA_CORRECT */
U8G_ESC_ADR(1), /* data mode */
0x3f,
0x25,
0x1c,
0x1e,
0x20,
0x12,
0x2a,
0x90,
0x24,
0x11,
0x00,
0x00,
0x00,
0x00,
0x00,
U8G_ESC_ADR(0), /* instruction mode */
0x0e1, /* NEGATIVE_GAMMA_CORRECT */
U8G_ESC_ADR(1), /* data mode */
0x20,
0x20,
0x20,
0x20,
0x05,
0x00,
0x15,
0xa7,
0x3d,
0x18,
0x25,
0x2a,
0x2b,
0x2b,
0x3a,
U8G_ESC_ADR(0), /* instruction mode */
0x0b1, /* FRAME_RATE_CONTROL1 */
U8G_ESC_ADR(1), /* data mode */
0x008, /* DIVA = 8 */
0x008, /* VPA = 8 */
U8G_ESC_ADR(0), /* instruction mode */
0x0b4, /* DISPLAY_INVERSION */
U8G_ESC_ADR(1), /* data mode */
0x007, /* NLA = 1, NLB = 1, NLC = 1 (all on Frame Inversion) */
U8G_ESC_ADR(0), /* instruction mode */
0x0c0, /* POWER_CONTROL1 */
U8G_ESC_ADR(1), /* data mode */
0x00a, /* VRH = 10: GVDD = 4.30 */
0x002, /* VC = 2: VCI1 = 2.65 */
U8G_ESC_ADR(0), /* instruction mode */
0x0c1, /* POWER_CONTROL2 */
U8G_ESC_ADR(1), /* data mode */
0x002, /* BT = 2: AVDD = 2xVCI1, VCL = -1xVCI1, VGH = 5xVCI1, VGL = -2xVCI1 */
U8G_ESC_ADR(0), /* instruction mode */
0x0c5, /* VCOM_CONTROL1 */
U8G_ESC_ADR(1), /* data mode */
0x050, /* VMH = 80: VCOMH voltage = 4.5 */
0x05b, /* VML = 91: VCOML voltage = -0.225 */
U8G_ESC_ADR(0), /* instruction mode */
0x0c7, /* VCOM_OFFSET_CONTROL */
U8G_ESC_ADR(1), /* data mode */
0x040, /* nVM = 0, VMF = 64: VCOMH output = VMH, VCOML output = VML */
U8G_ESC_ADR(0), /* instruction mode */
0x02a, /* SET_COLUMN_ADDRESS */
U8G_ESC_ADR(1), /* data mode */
0x000, /* */
0x000, /* */
0x000, /* */
0x07f, /* */
U8G_ESC_ADR(0), /* instruction mode */
0x02b, /* SET_PAGE_ADDRESS */
U8G_ESC_ADR(1), /* data mode */
0x000, /* */
0x000, /* */
0x000, /* */
0x07f, /* */
U8G_ESC_ADR(0), /* instruction mode */
0x036, /* SET_ADDRESS_MODE */
U8G_ESC_ADR(1), /* data mode */
0x000, /* Select display orientation */
U8G_ESC_ADR(0), /* instruction mode */
0x029, /* display on */
0x02c, /* write start */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
#endif
/* calculate bytes for Type B 4096 color display */
static uint8_t get_byte_1(uint8_t v)
{
v >>= 4;
v &= 0x0e;
return v;
}
static uint8_t get_byte_2(uint8_t v)
{
uint8_t w;
w = v;
w &= 3;
w = (w<<2) | w;
v <<= 3;
v &= 0x0e0;
w |= v;
return w;
}
uint8_t u8g_dev_st7687_c144mvgd_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7687_c144mvgd_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i, j;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x02a ); /* Column address set 8.1.20 */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteByte(u8g, dev, 0x000 ); /* x0 */
u8g_WriteByte(u8g, dev, WIDTH-1 ); /* x1 */
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x02b ); /* Row address set 8.1.21 */
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteByte(u8g, dev, y ); /* y0 */
u8g_WriteByte(u8g, dev, y+PAGE_HEIGHT-1 ); /* y1 */
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x02c ); /* Memory write 8.1.22 */
u8g_SetAddress(u8g, dev, 1); /* data mode */
for( i = 0; i < PAGE_HEIGHT; i ++ )
{
for( j = 0; j < WIDTH; j ++ )
{
u8g_WriteByte(u8g, dev, get_byte_1(*ptr) );
u8g_WriteByte(u8g, dev, get_byte_2(*ptr) );
ptr++;
}
}
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_st7687_c144mvgd_8h8_buf[WIDTH*8] U8G_NOCOMMON ;
u8g_pb_t u8g_st7687_c144mvgd_8h8_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_st7687_c144mvgd_8h8_buf};
u8g_dev_t u8g_dev_st7687_c144mvgd_sw_spi = { u8g_dev_st7687_c144mvgd_fn, &u8g_st7687_c144mvgd_8h8_pb, u8g_com_arduino_sw_spi_fn };
u8g_dev_t u8g_dev_st7687_c144mvgd_8bit = { u8g_dev_st7687_c144mvgd_fn, &u8g_st7687_c144mvgd_8h8_pb, U8G_COM_PARALLEL };

@ -0,0 +1,175 @@
/*
u8g_dev_st7920_128x64.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 128
#define HEIGHT 64
#define PAGE_HEIGHT 8
/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
static const uint8_t u8g_dev_st7920_128x64_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_DLY(100), /* 8 Dez 2012: additional delay 100 ms because of reset*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
0x038, /* 8 Bit interface (DL=1), basic instruction set (RE=0) */
0x00c, /* display on, cursor & blink off; 0x08: all off */
0x006, /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */
0x002, /* disable scroll, enable CGRAM adress */
0x001, /* clear RAM, needs 1.6 ms */
U8G_ESC_DLY(100), /* delay 100 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
if ( y < 32 )
{
u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
}
else
{
u8g_WriteByte(u8g, dev, 0x080 | (y-32) ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 | 8); /* set x pos to 64*/
}
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7920_128x64_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < 32; i ++ )
{
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
if ( y < 32 )
{
u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
}
else
{
u8g_WriteByte(u8g, dev, 0x080 | (y-32) ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 | 8); /* set x pos to 64*/
}
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7920_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_ST7920_SW_SPI);
U8G_PB_DEV(u8g_dev_st7920_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_ST7920_HW_SPI);
U8G_PB_DEV(u8g_dev_st7920_128x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_FAST_PARALLEL);
U8G_PB_DEV(u8g_dev_st7920_128x64_custom, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, u8g_com_arduino_st7920_custom_fn);
#define QWIDTH (WIDTH*4)
uint8_t u8g_dev_st7920_128x64_4x_buf[QWIDTH] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7920_128x64_4x_pb = { {32, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7920_128x64_4x_buf};
u8g_dev_t u8g_dev_st7920_128x64_4x_sw_spi = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_ST7920_SW_SPI };
u8g_dev_t u8g_dev_st7920_128x64_4x_hw_spi = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_ST7920_HW_SPI };
u8g_dev_t u8g_dev_st7920_128x64_4x_8bit = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_FAST_PARALLEL };
u8g_dev_t u8g_dev_st7920_128x64_4x_custom = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, u8g_com_arduino_st7920_custom_fn };

@ -0,0 +1,151 @@
/*
u8g_dev_st7920_192x32.c
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 192
#define HEIGHT 32
/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
static const uint8_t u8g_dev_st7920_192x32_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_DLY(100), /* 8 Dez 2012: additional delay 100 ms because of reset*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
0x038, /* 8 Bit interface (DL=1), basic instruction set (RE=0) */
0x00c, /* display on, cursor & blink off; 0x08: all off */
0x006, /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */
0x002, /* disable scroll, enable CGRAM adress */
0x001, /* clear RAM, needs 1.6 ms */
U8G_ESC_DLY(100), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7920_192x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_192x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7920_192x32_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_192x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < 32; i ++ )
{
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7920_192x32_sw_spi, WIDTH, HEIGHT, 8, u8g_dev_st7920_192x32_fn, U8G_COM_ST7920_SW_SPI);
U8G_PB_DEV(u8g_dev_st7920_192x32_hw_spi, WIDTH, HEIGHT, 8, u8g_dev_st7920_192x32_fn, U8G_COM_ST7920_HW_SPI);
U8G_PB_DEV(u8g_dev_st7920_192x32_8bit, WIDTH, HEIGHT, 8, u8g_dev_st7920_192x32_fn, U8G_COM_FAST_PARALLEL);
#define QWIDTH (WIDTH*4)
uint8_t u8g_dev_st7920_192x32_4x_buf[QWIDTH] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7920_192x32_4x_pb = { {32, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7920_192x32_4x_buf};
u8g_dev_t u8g_dev_st7920_192x32_4x_sw_spi = { u8g_dev_st7920_192x32_4x_fn, &u8g_dev_st7920_192x32_4x_pb, U8G_COM_ST7920_SW_SPI };
u8g_dev_t u8g_dev_st7920_192x32_4x_hw_spi = { u8g_dev_st7920_192x32_4x_fn, &u8g_dev_st7920_192x32_4x_pb, U8G_COM_ST7920_HW_SPI };
u8g_dev_t u8g_dev_st7920_192x32_4x_8bit = { u8g_dev_st7920_192x32_4x_fn, &u8g_dev_st7920_192x32_4x_pb, U8G_COM_FAST_PARALLEL };

@ -0,0 +1,154 @@
/*
u8g_dev_st7920_202x32.c
tested with CFAG20232
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g.h"
#define WIDTH 202
#define HEIGHT 32
#define PAGE_HEIGHT 8
/* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
static const uint8_t u8g_dev_st7920_202x32_init_seq[] PROGMEM = {
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_ADR(0), /* instruction mode */
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
U8G_ESC_DLY(100), /* 8 Dez 2012: additional delay 100 ms because of reset*/
U8G_ESC_CS(1), /* enable chip */
U8G_ESC_DLY(50), /* delay 50 ms */
0x038, /* 8 Bit interface (DL=1), basic instruction set (RE=0) */
0x00c, /* display on, cursor & blink off; 0x08: all off */
0x006, /* Entry mode: Cursor move to right ,DDRAM address counter (AC) plus 1, no shift */
0x002, /* disable scroll, enable CGRAM adress */
0x001, /* clear RAM, needs 1.6 ms */
U8G_ESC_DLY(100), /* delay 10 ms */
U8G_ESC_CS(0), /* disable chip */
U8G_ESC_END /* end of sequence */
};
uint8_t u8g_dev_st7920_202x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_202x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < 8; i ++ )
{
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7920_202x32_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
case U8G_DEV_MSG_INIT:
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_202x32_init_seq);
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t y, i;
uint8_t *ptr;
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_SetChipSelect(u8g, dev, 1);
y = pb->p.page_y0;
ptr = pb->buf;
for( i = 0; i < 32; i ++ )
{
u8g_SetAddress(u8g, dev, 0); /* cmd mode */
u8g_WriteByte(u8g, dev, 0x03e ); /* enable extended mode */
u8g_WriteByte(u8g, dev, 0x080 | y ); /* y pos */
u8g_WriteByte(u8g, dev, 0x080 ); /* set x pos to 0*/
u8g_SetAddress(u8g, dev, 1); /* data mode */
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
ptr += WIDTH/8;
y++;
}
u8g_SetChipSelect(u8g, dev, 0);
}
break;
}
return u8g_dev_pb32h1_base_fn(u8g, dev, msg, arg);
}
U8G_PB_DEV(u8g_dev_st7920_202x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_202x32_fn, U8G_COM_ST7920_SW_SPI);
U8G_PB_DEV(u8g_dev_st7920_202x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_202x32_fn, U8G_COM_ST7920_HW_SPI);
U8G_PB_DEV(u8g_dev_st7920_202x32_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_202x32_fn, U8G_COM_FAST_PARALLEL);
#define QWIDTH (WIDTH*4)
uint8_t u8g_dev_st7920_202x32_4x_buf[QWIDTH] U8G_NOCOMMON ;
u8g_pb_t u8g_dev_st7920_202x32_4x_pb = { {32, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7920_202x32_4x_buf};
u8g_dev_t u8g_dev_st7920_202x32_4x_sw_spi = { u8g_dev_st7920_202x32_4x_fn, &u8g_dev_st7920_202x32_4x_pb, U8G_COM_ST7920_SW_SPI };
u8g_dev_t u8g_dev_st7920_202x32_4x_hw_spi = { u8g_dev_st7920_202x32_4x_fn, &u8g_dev_st7920_202x32_4x_pb, U8G_COM_ST7920_HW_SPI };
u8g_dev_t u8g_dev_st7920_202x32_4x_8bit = { u8g_dev_st7920_202x32_4x_fn, &u8g_dev_st7920_202x32_4x_pb, U8G_COM_FAST_PARALLEL };

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save