Class: Denko::Display::ST7565
- Inherits:
-
Object
- Object
- Denko::Display::ST7565
- Includes:
- Behaviors::Lifecycle, SPICommon
- Defined in:
- lib/denko/display/st7565.rb
Constant Summary collapse
- COLUMNS =
128- ROWS =
64- RESET =
Overall commands
0b11100010- DISPLAY_ON =
0b10101111- DISPLAY_OFF =
0b10101110- ALL_POINTS_OFF =
0b10100100- ALL_POINTS_ON =
0b10100100- STATIC_INDICATOR_OFF =
0b10101100- STATIC_INDICATOR_ON =
0b10101101- POWER_CONTROL =
Overall votage commands
0b00101000- LCD_BIAS_1_7 =
0b10100011- VOLUME =
0b10000001- VALID_VOLUMES =
(0..63).to_a
- RESISTOR_RATIO =
Control voltage regulator circuit. Values 0-7 are OR’ed into last 3 bits. 5 seems to work best for non-inverted mode, and 6 for inverted.
0b00100000- VALID_RESISTOR_RATIOS =
(0..7).to_a
- RMW_WRITE =
Addressing and writing to display RAM. Always in write mode. Called Read-Modify-Write and END in datasheet.
0b11100000- RMW_END =
0b11101110- PASET =
Set page and column to start on before writing data. Page and column nibbles are OR’ed into lower 4 bits.
0b10110000- CASET_UPPER =
0b00010000- CASET_LOWER =
0b00000000- COL_NORMAL =
Control X and Y mirroring, so the display can be reflected in either axis, or rotated 180 degrees, in hardware.
How RAM columns map to pixels. Called ADC in datasheet.
0b10100000- COL_REVERSE =
0b10100001- PAGE_NORMAL =
How RAM pages map to pixels. Called Common Output Mode in datasheet.
0b11000000- PAGE_REVERSE =
0b11001000- COL_REVERSE_COL_START =
RAM has 132 columns. Need to start at index 4 when columns get reversed.
4- INVERT_OFF =
Control display inversion. White on black is OFF. Black on white ON.
0b10100110- INVERT_ON =
0b10100111
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
Attributes included from Behaviors::Component
Attributes included from Behaviors::MultiPin
Instance Method Summary collapse
- #draw_partial(buffer, x_start, x_finish, p_start, p_finish, color = 1) ⇒ Object
- #invert ⇒ Object
- #reflect_x ⇒ Object
- #reflect_y ⇒ Object
- #resistor_ratio=(ratio) ⇒ Object
- #rotate ⇒ Object
- #slp ⇒ Object
- #standby ⇒ Object
- #volume=(value) ⇒ Object
- #wake ⇒ Object
- #x_ram_offset ⇒ Object
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
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #pre_callback_filter, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::BusPeripheral
Methods included from Behaviors::Component
Methods included from Behaviors::MultiPin
#convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins
Instance Method Details
#draw_partial(buffer, x_start, x_finish, p_start, p_finish, color = 1) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/denko/display/st7565.rb', line 144 def draw_partial(buffer, x_start, x_finish, p_start, p_finish, color=1) x = x_start + x_ram_offset x_lower4 = (x & 0b00001111) x_upper4 = (x & 0b11110000) >> 4 (p_start..p_finish).each do |page| command [RMW_WRITE] # Set start page and column. command [PASET | page, CASET_LOWER | x_lower4, CASET_UPPER | x_upper4] # 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) } command [RMW_END] end end |
#invert ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/denko/display/st7565.rb', line 104 def invert @inverted ||= false if @inverted command [INVERT_OFF] self.resistor_ratio = 5 else command [INVERT_ON] self.resistor_ratio = 6 end @inverted = !@inverted end |
#reflect_x ⇒ Object
81 82 83 84 85 86 |
# File 'lib/denko/display/st7565.rb', line 81 def reflect_x @reflected_x ||= false @reflected_x ? command([COL_NORMAL]) : command([COL_REVERSE]) @reflected_x = !@reflected_x @x_ram_offset = @reflected_x ? COL_REVERSE_COL_START : 0 end |
#reflect_y ⇒ Object
88 89 90 91 92 |
# File 'lib/denko/display/st7565.rb', line 88 def reflect_y @reflected_y ||= false @reflected_y ? command([PAGE_NORMAL]) : command([PAGE_REVERSE]) @reflected_y = !@reflected_y end |
#resistor_ratio=(ratio) ⇒ Object
43 44 45 46 |
# File 'lib/denko/display/st7565.rb', line 43 def resistor_ratio=(ratio) raise ArgumentError, "invalid resistor ratio #{ratio}" unless VALID_RESISTOR_RATIOS.include? ratio command [RESISTOR_RATIO | ratio] end |
#rotate ⇒ Object
94 95 96 97 |
# File 'lib/denko/display/st7565.rb', line 94 def rotate reflect_x reflect_y end |
#slp ⇒ Object
23 24 25 |
# File 'lib/denko/display/st7565.rb', line 23 def slp command [STATIC_INDICATOR_OFF, 0b00, DISPLAY_OFF, ALL_POINTS_ON] end |
#standby ⇒ Object
19 20 21 |
# File 'lib/denko/display/st7565.rb', line 19 def standby command [DISPLAY_OFF, ALL_POINTS_ON] end |
#volume=(value) ⇒ Object
48 49 50 51 |
# File 'lib/denko/display/st7565.rb', line 48 def volume=(value) raise ArgumentError, "invalid volume #{value}" unless VALID_VOLUMES.include? value command [VOLUME, value] end |
#wake ⇒ Object
27 28 29 30 |
# File 'lib/denko/display/st7565.rb', line 27 def wake # Note static indicator stays disabled. Not sure how to use it. command [ALL_POINTS_OFF, DISPLAY_ON, STATIC_INDICATOR_OFF, 0b00] end |
#x_ram_offset ⇒ Object
77 78 79 |
# File 'lib/denko/display/st7565.rb', line 77 def x_ram_offset @x_ram_offset ||= 0 end |