Skip to content

Commit

Permalink
Fix height for PhatSSD1608 and do minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mnishiguchi committed Nov 9, 2021
1 parent 2060e89 commit 2b4f9b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/display/display.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ defmodule Inky.Display do
def spec_for(type, accent \\ :black)

def spec_for(type = :phat_ssd1608, accent) do
# Keep it minimal. Details are specified in `Inky.HAL.PhatSSD1608`.
%__MODULE__{
type: type,
width: 250,
height: 122,
height: 136,
packed_dimensions: %{},
rotation: -90,
accent: accent,
Expand Down
22 changes: 11 additions & 11 deletions lib/hal/hal_ssd1608.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ defmodule Inky.HAL.PhatSSD1608 do
@color_map_black %{black: 0, miss: 1}
@color_map_accent %{red: 1, yellow: 1, accent: 1, miss: 0}

@cols 136
@rows 250
@rotation -90
@lut_data <<0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69, 0x69, 0x59, 0x58, 0x99,
0x99, 0x88, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, 0x35, 0x51, 0x51, 0x19,
0x01, 0x00>>
Expand Down Expand Up @@ -71,14 +68,15 @@ defmodule Inky.HAL.PhatSSD1608 do

@impl Inky.HAL
def handle_update(pixels, border, push_policy, state = %State{}) do
black_bits = PixelUtil.pixels_to_bits(pixels, @rows, @cols, @rotation, @color_map_black)
accent_bits = PixelUtil.pixels_to_bits(pixels, @rows, @cols, @rotation, @color_map_accent)
%{width: width, height: height, rotation: rotation} = state.display
black_bits = PixelUtil.pixels_to_bits(pixels, width, height, rotation, @color_map_black)
accent_bits = PixelUtil.pixels_to_bits(pixels, width, height, rotation, @color_map_accent)

state |> set_reset(0) |> sleep(500) |> set_reset(1) |> sleep(500)
state |> write_command(@cmd_soft_reset) |> sleep(1000)

case pre_update(state, push_policy) do
:cont -> do_update(state, state.display, border, black_bits, accent_bits)
:cont -> do_update(state, border, black_bits, accent_bits)
:halt -> {:error, :device_busy}
end
end
Expand All @@ -100,15 +98,17 @@ defmodule Inky.HAL.PhatSSD1608 do
end
end

@spec do_update(State.t(), Inky.Display.t(), atom(), binary(), binary()) :: :ok
defp do_update(state, _display, border, black_bits, accent_bits) do
@spec do_update(State.t(), atom(), binary(), binary()) :: :ok
defp do_update(state, border, black_bits, accent_bits) do
%{width: width, height: height} = state.display

state
|> write_command(@cmd_set_driver_output, [@rows - 1, (@rows - 1) >>> 8, 0x00])
|> write_command(@cmd_set_driver_output, [width - 1, (width - 1) >>> 8, 0x00])
|> write_command(@cmd_set_dummy_line_period, [0x1B])
|> write_command(@cmd_set_gate_line_width, [0x0B])
|> write_command(@cmd_set_data_entry_mode, [0x03])
|> write_command(@cmd_set_ram_x_position, [0x00, div(@cols, 8) - 1])
|> write_command(@cmd_set_ram_y_position, [0x00, 0x00, @rows - 1, (@rows - 1) >>> 8])
|> write_command(@cmd_set_ram_x_position, [0x00, div(height, 8) - 1])
|> write_command(@cmd_set_ram_y_position, [0x00, 0x00, width - 1, (width - 1) >>> 8])
|> write_command(@cmd_write_vcom, [0x70])
|> write_command(@cmd_write_lut, @lut_data)
|> set_border_color(border)
Expand Down

0 comments on commit 2b4f9b6

Please sign in to comment.