Class: Denko::Display::IL0373

Inherits:
Object
  • Object
show all
Includes:
Behaviors::Lifecycle, SPIEPaperCommon
Defined in:
lib/denko/display/il0373.rb

Constant Summary collapse

COLUMNS =
212
ROWS =
104
PANEL_SETTING =

Subset of used commands from datasheet:

0x00
POWER_SETTING =
0x01
POWER_OFF =
0x02
POWER_OFF_SEQUENCE =
0x03
POWER_ON =
0x04
POWER_ON_MEASURE =
0x05
BOOSTER_SOFT_START =
0x06
DEEP_SLEEP =
0x07
DATA_START_1 =
0x10
DATA_STOP =
0x11
DISPLAY_REFRESH =
0x12
DATA_START_2 =
0x13
VCOM_DATA_SETTING =
0x50
RESOLUTION_SETTING =
0x61
PARTIAL_WINDOW =
0x90
PARTIAL_IN =
0x91
PARTIAL_OUT =
0x92

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Constants included from SPIEPaperCommon

SPIEPaperCommon::BUSY_WAIT_TIME, SPIEPaperCommon::RESET_TIME

Instance Attribute Summary

Attributes included from SPI::Peripheral

#spi_bit_order, #spi_frequency, #spi_mode

Attributes included from Behaviors::State

#state

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Instance Method Summary collapse

Methods included from Behaviors::Lifecycle

included

Methods included from SPIEPaperCommon

#busy_wait, #hw_reset, #initialize_pins

Methods included from SPICommon

#command, #data, #initialize_pins, #transfer_limit

Methods included from PixelCommon

#canvas, #colors, #columns, #get_partial_buffer, #p_max, #p_min, #rows, #x_max, #x_min, #y_max, #y_min

Methods included from SPI::Peripheral

#ensure_byte_array, #initialize_pins, #proxy_pin, #spi_listen, #spi_read, #spi_stop, #spi_transfer, #spi_write, #update

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #pre_callback_filter, #remove_callback, #update

Methods included from Behaviors::State

#update_state

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::MultiPin

#convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins

Instance Method Details

#booster_soft_startObject



108
109
110
111
112
# File 'lib/denko/display/il0373.rb', line 108

def booster_soft_start
  # Defaults from datasheet.
  command [BOOSTER_SOFT_START]
  data    [0x17, 0x17, 0x17]
end

#deep_sleepObject



129
130
131
132
133
# File 'lib/denko/display/il0373.rb', line 129

def deep_sleep
  # Default from datasheet.
  command [DEEP_SLEEP]
  data    [0xA5]
end

#draw(*args, **kwargs) ⇒ Object



150
151
152
153
# File 'lib/denko/display/il0373.rb', line 150

def draw(*args, **kwargs)
  wake
  super(*args, **kwargs)
end

#draw_partial(buffer, x_start, x_finish, p_start, p_finish, color = 1) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/denko/display/il0373.rb', line 155

def draw_partial(buffer, x_start, x_finish, p_start, p_finish, color=1)
  set_window(x_start, x_finish, p_start, p_finish)

  if (colors == 2)
    # In B/W/Red mode, red goes in DATA2, black in DATA1
    (color == 2) ? command[DATA_START_2] : command[DATA_START_1]
  else
    # In B/W mode, always write to DATA2
    command [DATA_START_2]
  end

  # Can't control address increment to go horizontally, always vertical.
  # So get partial from the full buffer and reorder the bytes.
  transformed_buffer = []
  (x_start..x_finish).each do |x|
    (p_start..p_finish).to_a.reverse.each do |page|
      index = (page * columns) + x
      transformed_buffer << buffer[index]
    end
  end
  transformed_buffer.each_slice(transfer_limit) { |slice| data(slice) }

  command [DATA_STOP]
end

#invert_blackObject



95
96
97
# File 'lib/denko/display/il0373.rb', line 95

def invert_black
  @invert_black = !@invert_black
end

#power_onObject



114
115
116
117
# File 'lib/denko/display/il0373.rb', line 114

def power_on
  command [POWER_ON]
  busy_wait
end

#reflect_xObject



65
66
67
# File 'lib/denko/display/il0373.rb', line 65

def reflect_x
  @reflect_x = !@reflect_x
end

#reflect_yObject



69
70
71
# File 'lib/denko/display/il0373.rb', line 69

def reflect_y
  @reflect_y = !@reflect_y
end

#refreshObject



180
181
182
183
# File 'lib/denko/display/il0373.rb', line 180

def refresh
  command [DISPLAY_REFRESH]
  busy_wait
end

#rotateObject



73
74
75
76
# File 'lib/denko/display/il0373.rb', line 73

def rotate
  @reflect_x = !@reflect_x
  @reflect_y = !@reflect_y
end

#set_panel_settingObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/denko/display/il0373.rb', line 35

def set_panel_setting
  # NOT DEFAULTS
  # From datasheet:
  #   Bits 7..6: Enable all source and gate channels
  #       Bit 5: 0 = LUT from OTP
  #       Bit 4: 0 = B/W/R mode, 1 = B/W mode
  #       Bit 3: 0 = Gate scan decrements (1 increments)
  #       Bit 2: 0 = Source scan decrements (1 increments)
  #       Bit 1: 1 = Enable booster
  #       Bit 0: 1 = Soft reset
  value  = 0b0000_0011

  # Handle colors
  value |= (1 << 4) if colors == 2

  # Handle screen size
  source_gate_bits = 0b11
  source_gate_bits = 0b10 if (rows <= 128)
  source_gate_bits = 0b01 if (rows <= 96) && (columns <= 252)
  source_gate_bits = 0b00 if (rows <= 96) && (columns <= 230)
  value |= source_gate_bits

  # Handle hardware reflection/rotation
  value |= (1 << 2) if @reflect_y
  value |= (1 << 3) if @reflect_x

  command [PANEL_SETTING]
  data    [value]
end

#set_power_settingObject



29
30
31
32
33
# File 'lib/denko/display/il0373.rb', line 29

def set_power_setting
  # Defaults from datasheet.
  command [POWER_SETTING]
  data    [0x03, 0x00, 0x26, 0x26, 0x03]
end

#set_resolutionObject



99
100
101
102
103
104
105
106
# File 'lib/denko/display/il0373.rb', line 99

def set_resolution
  command [RESOLUTION_SETTING]
  data [
    p_max+1 << 3,
    (columns >> 8) & 0b1,
    columns & 0xFF
  ]
end

#set_vcom_data_settingObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/denko/display/il0373.rb', line 78

def set_vcom_data_setting
  # Default value from data sheet.
  value = 0b0000_0111

  # Datsheet may be wrong here. Bit 5 set seems to always invert DATA2, so Bit 4 does DATA1?
  #   In B/W mode:   set bit 5 to avoid black channel inversion relative to Canvas.
  #   In B/W/R mode: set bit 4 to avoid black channel inversion relative to Canvas.
  if (colors == 2)
    value |= (1 << 4) unless @invert_black
  else
    value |= (1 << 5) unless @invert_black
  end

  command [VCOM_DATA_SETTING]
  data    [value]
end

#set_window(x_start = x_min, x_finish = x_max, p_start = p_min, p_finish = p_max) ⇒ Object

Treat what the datasheet calls x as vertical (y, page), and vertical as horizontal (x).



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/denko/display/il0373.rb', line 136

def set_window(x_start=x_min, x_finish=x_max, p_start=p_min, p_finish=p_max)
  command [PARTIAL_WINDOW]
  data [
    p_start  << 3,
    p_finish << 3,
    (x_start >> 8) & 0b1,
    x_start & 0xFF,
    (x_finish >> 8) & 0b1,
    x_finish & 0xFF,
    0b0
  ]
  command [PARTIAL_IN]
end

#wakeObject



119
120
121
122
123
124
125
126
127
# File 'lib/denko/display/il0373.rb', line 119

def wake
  hw_reset
  set_power_setting
  set_panel_setting
  set_vcom_data_setting
  set_resolution
  booster_soft_start
  power_on
end