Class: Denko::Display::PCD8544

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

Constant Summary collapse

COLUMNS =
84
ROWS =
48
FUNCTION_SET =
0b00100000
POWER_UP =

OR these options into lowest 3 bits:

0b000
POWER_DOWN =
0b100
H_ADDRESSING =
0b00
V_ADDRESSING =
0b10
BASIC_INS_SET =
0b0
EXT_INS_SET =
0b1
DISPLAY_CONTROL_SET =

Basic Instruciton Set (H = 0)

0b00001000
DISPLAY_BLANK =

OR these options into lowest 3 bits:

0b000
DISPLAY_NORMAL =
0b100
DISPLAY_ALL_SEGS =
0b001
DISPLAY_INVERT =
0b101
RAM_Y_SET =

OR Y value into lowest 3 bits

0b01000000
RAM_X_SET =

OR X value into lowest 7 bits

0b10000000
TEMP_COEFF_SET =

Extended Instruciton Set (H = 1)

0b00000100
BIAS_SET =

OR temperature coeff. into lowest 2 bits

0b00010000
VOP_SET =

OR bias system values into lowest 3 bits

0b10000000
VALID_VOPS =
(0..127).to_a
VALID_BIASES =
(0..7).to_a
VALID_TCOEFFS =
(0..3).to_a

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

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 SPICommon

#command, #data, #initialize_pins, #transfer_limit

Methods included from PixelCommon

#canvas, #colors, #columns, #draw, #get_partial_buffer, #p_max, #p_min, #refresh, #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::Lifecycle

included

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

#all_segments_onObject



113
114
115
# File 'lib/denko/display/pcd8544.rb', line 113

def all_segments_on
  set_display_control(DISPLAY_ALL_SEGS)
end

#basic_instruction_modeObject



49
50
51
52
# File 'lib/denko/display/pcd8544.rb', line 49

def basic_instruction_mode
  @function_state = (function_state & 0b11111110) | BASIC_INS_SET
  command [function_state]
end

#biasObject



97
98
99
# File 'lib/denko/display/pcd8544.rb', line 97

def bias
  @bias ||= 0
end

#bias=(value) ⇒ Object

Raises:

  • (ArgumentError)


75
76
77
78
79
80
81
# File 'lib/denko/display/pcd8544.rb', line 75

def bias=(value)
  raise ArgumentError, "invalid bias: #{value}" unless VALID_BIASES.include?(value)
  extended_instruction_mode
  command [BIAS_SET | value]
  basic_instruction_mode
  @bias = value
end

#blankObject



109
110
111
# File 'lib/denko/display/pcd8544.rb', line 109

def blank
  set_display_control(DISPLAY_BLANK)
end

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



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

def draw_partial(buffer, x_start, x_finish, p_start, p_finish, color=1)
  # Always use horizontal addressing mode.
  basic_instruction_mode

  (p_start..p_finish).each do |page|
    # Set start page and column.
    command [RAM_X_SET | x_start, RAM_Y_SET | page]

    # Get needed bytes for this page only.
    src_start       = (columns * page) + x_start
    src_end         = (columns * page) + x_finish
    partial_buffer  = buffer[src_start..src_end]

    # Send in chunks up to maximum transfer size.
    partial_buffer.each_slice(transfer_limit) { |slice| data(slice) }
  end
end

#extended_instruction_modeObject



54
55
56
57
# File 'lib/denko/display/pcd8544.rb', line 54

def extended_instruction_mode
  @function_state = (function_state & 0b11111110) | EXT_INS_SET
  command [function_state]
end

#function_stateObject



59
60
61
# File 'lib/denko/display/pcd8544.rb', line 59

def function_state
  @function_state ||= FUNCTION_SET
end

#invertObject



117
118
119
120
121
# File 'lib/denko/display/pcd8544.rb', line 117

def invert
  @inverted = !@inverted
  value = @inverted ? DISPLAY_INVERT : DISPLAY_NORMAL
  set_display_control(value)
end

#power_downObject



44
45
46
47
# File 'lib/denko/display/pcd8544.rb', line 44

def power_down
  @function_state = (function_state & 0b11111011) | POWER_DOWN
  command [function_state]
end

#power_upObject

OR VOP values into lowest 7 bits



39
40
41
42
# File 'lib/denko/display/pcd8544.rb', line 39

def power_up
  @function_state = (function_state & 0b11111011) | POWER_UP
  command [function_state]
end

#set_display_control(value) ⇒ Object



105
106
107
# File 'lib/denko/display/pcd8544.rb', line 105

def set_display_control(value)
  command [DISPLAY_CONTROL_SET | value]
end

#temperature_coefficientObject



101
102
103
# File 'lib/denko/display/pcd8544.rb', line 101

def temperature_coefficient
  @temperature_coefficient ||= 0
end

#temperature_coefficient=(value) ⇒ Object

Raises:

  • (ArgumentError)


85
86
87
88
89
90
91
# File 'lib/denko/display/pcd8544.rb', line 85

def temperature_coefficient=(value)
  raise ArgumentError, "invalid temperature coefficient: #{value}" unless VALID_TCOEFFS.include?(value)
  extended_instruction_mode
  command [TEMP_COEFF_SET | value]
  basic_instruction_mode
  @temperature_coefficient = value
end

#vopObject



93
94
95
# File 'lib/denko/display/pcd8544.rb', line 93

def vop
  @vop ||= 0
end

#vop=(value) ⇒ Object

Raises:

  • (ArgumentError)


65
66
67
68
69
70
71
# File 'lib/denko/display/pcd8544.rb', line 65

def vop=(value)
  raise ArgumentError, "invalid Vop: #{value}" unless VALID_VOPS.include?(value)
  extended_instruction_mode
  command [VOP_SET | value]
  basic_instruction_mode
  @vop = value
end