-
Notifications
You must be signed in to change notification settings - Fork 12
Correct height for PhatSSD1608 and do minor refactoring #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>> | ||
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did rows become width here? This means that the axes have been swapped, was that done on purpose? This will break code that is built on the current dimensions. |
||
|
|
||
| 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 | ||
|
|
@@ -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]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible axes swap, see my earlier comment. |
||
| |> 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]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible axes swap, see my earlier comment. |
||
| |> write_command(@cmd_write_vcom, [0x70]) | ||
| |> write_command(@cmd_write_lut, @lut_data) | ||
| |> set_border_color(border) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see corrections :)!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That magic number 136 was not explained in the Python library. The actual dimension is 250*122 in their catalog. Possibly it is because 122 is not divisible by 8.
So far my pHAT SSD1608 is working well. Before this PR, the image is slightly off center.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, so if the height is 122, the image gets cropped on the right side in the photo above, right? I guess this is similar to how iPhones recently have gotten a notch, except that it's not in the centre-top here, but instead in the top-right/bottom/left (depending on orientation). By the way, did you add support for this screen in a separate PR? If so, did you follow the flow of data/constants internally to track down where width/height might be used during setup? It would be good to verify that hardware initialisation isn't changed from how the python code does it.
The code should probably expose 122 as the height, but internally adjust things, to offset the pixels so that the entire image is shown. If the screen is meant to have 250x122 addressable pixels, I think it's best if we act as if that were the case. What do you think?
For fun, we could have an extended mode that allows you to use the extra pixels in the corner, but that is probably something for a separate, later, PR, hah.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top or bottom might be cropped. Yeah the Python library uses an image processing library to do some adjustment, but I am not familiar with all the image processing.
Sidenote: In my fork, I make the display up side down so it is consistent with manufacturer's example code.
https://github.com/pimoroni/inky/blob/fc17026df35447c1147e9bfa38988e89e75c80e6/examples/name-badge.py#L66