Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7d80cce
Start work on on Inky Impression
lawik Oct 10, 2021
8ee2dda
More work on setup and update for Inky Impression
lawik Oct 27, 2021
6e11741
Add all of the Impression code but not working, added cs0 but that wo…
lawik Oct 27, 2021
c56c9be
Kinda working!
axelson Nov 8, 2021
e415e0e
Kind of like a flag
axelson Nov 8, 2021
fc37b1f
Cleaning
axelson Nov 9, 2021
cc82eda
Clean up cs pin calls
axelson Nov 9, 2021
99d2cd5
clean
axelson Nov 9, 2021
7a636df
Merge pull request #42 from axelson/jax/inky-impression
lawik Nov 9, 2021
753d5a8
Fix log typo
Jul 3, 2022
3f46d9a
Adds comments to byte commands defined for Impression in hal
Jul 3, 2022
3142798
Fix typo in comment
Jul 3, 2022
ae2e48f
Update mix deps for development on jasonmj
Jul 3, 2022
07f75e6
Update display definition for impression
Jul 3, 2022
63cdb4f
Add handling for impression in packed_width and packed_height
Jul 3, 2022
13793cd
Fix usage of state in log function
Jul 3, 2022
853021b
Add set_dimensions to do_update for impression
Jul 3, 2022
46a3b40
Replace buffer generation with PixelUtil.pixels_to_bits
Jul 3, 2022
9dfa181
Add a color_map for the impression
Jul 3, 2022
5bfb57f
Add notes about WIP toward impression support
Jul 3, 2022
4689834
Reverting dev changes to mix.exs
Jul 3, 2022
3bcf4f1
Cleaning up unused code
Jul 8, 2022
590c25f
Adding bit_size option to PixelUtil.pixels_to_bits
Jul 8, 2022
d5bca11
Merge pull request #46 from jasonmj/impression
lawik Jul 11, 2022
9abc79f
Cleans up code for PR
Jul 12, 2022
80bdee8
Adds painter test
Jul 12, 2022
f86d1b8
Support circuits_gpio 1.0
axelson Jul 13, 2022
b30be19
Merge pull request #47 from axelson/impression
Jul 13, 2022
a68e31a
Add support for buttons on Inky Impression
Jul 23, 2022
40cda84
Support sending button messages to a process by registered atom name
Aug 1, 2022
6a6cd42
Merge pull request #48 from jasonmj/impression
lawik Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/display/display.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Inky.Display do
type: type,
width: 600,
height: 448,
packed_dimensions: nil,
packed_resolution: <<2, 88, 1, 192>>, # I used the struct.pack in Python to generate this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some observations...

(2*255 + 88) = 600-2 = 598
(1*255 + 192) = 488-1 = 447

How do these numbers relate to whatever input you put into python? Also, if we're not going to do this properly in elixir, we should at the very least have the actual code here, not just a mention of "it was done in python".

The dimensions for the Inky were kept in a struct, why not do the same thing here and convert it to a binary when it's required?

rotation: 0,
accent: nil,
}
Expand Down
109 changes: 104 additions & 5 deletions lib/hal/impression/rpihal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,45 @@ defmodule Inky.Impression.RpiHAL do

@behaviour Inky.HAL

@color_map_black %{black: 0, miss: 1}
@color_map_accent %{red: 1, yellow: 1, accent: 1, miss: 0}
@colors %{
:black => 0,
:white => 1,
:green => 2,
:blue => 3,
:red => 4,
:yellow => 5,
:orange => 6,
:clean => 7

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be named clear

}

@psr 0x00
@pwr 0x01
@pof 0x02
@pfs 0x03
@pon 0x04
@btst 0x06
@dslp 0x07
@dtm1 0x10
@dsp 0x11
@drf 0x12
@ipc 0x13
@pll 0x30
@tsc 0x40
@tse 0x41
@tws 0x42
@tsr 0x43
@cdi 0x50
@lpd 0x51
@tcon 0x60
@tres 0x61
@dam 0x65
@rev 0x70
@flg 0x71
@amv 0x80
@vv 0x81
@vdcs 0x82
@pws 0xE3
@tsset 0xE5

alias Inky.Display
alias Inky.HAL
Expand Down Expand Up @@ -52,7 +89,6 @@ defmodule Inky.Impression.RpiHAL do
accent_bits = PixelUtil.pixels_to_bits(pixels, w, h, r, @color_map_accent)

reset(state)
soft_reset(state)

case pre_update(state, push_policy) do
:cont -> do_update(state, display, border, black_bits, accent_bits)
Expand All @@ -77,9 +113,18 @@ defmodule Inky.Impression.RpiHAL do
end

defp do_update(state, display, border, buf_black, buf_accent) do
d_pd = display.packed_dimensions

state
|> set_resolution(display.packed_resolution)
|> set_panel()
|> set_power()
|> set_pll_clock_frequency()
|> set_tse_register()
|> set_vcom_data_interval_setting(border)
|> set_gate_source_data_interval_setting()
|> disable_external_flash()
|> set_pws_whatever_that_means()
# TODO: Continue with update here from https://github.com/pimoroni/inky/blob/master/library/inky/inky_uc8159.py#L311

|> set_analog_block_control()
|> set_digital_block_control()
|> set_gate(d_pd.height)
Expand Down Expand Up @@ -118,6 +163,60 @@ defmodule Inky.Impression.RpiHAL do
end

defp soft_reset(state), do: write_command(state, 0x12)

# >HH struct.pack, so big-endian, unsigned-sort * 2
defp set_resolution(state, packed_resolution), do: write_command(state, @tres, packed_resolution)

# Panel Setting
# 0b11000000 = Resolution select, 0b00 = 640x480, our panel is 0b11 = 600x448
# 0b00100000 = LUT selection, 0 = ext flash, 1 = registers, we use ext flash
# 0b00010000 = Ignore
# 0b00001000 = Gate scan direction, 0 = down, 1 = up (default)
# 0b00000100 = Source shift direction, 0 = left, 1 = right (default)
# 0b00000010 = DC-DC converter, 0 = off, 1 = on
# 0b00000001 = Soft reset, 0 = Reset, 1 = Normal (Default)
defp set_panel(state), do: write_command(state, @psr, [0b11101111, 0x08]

defp set_power(state), do: write_command(state, @pwr, [
Bitwise.bor(
Bitwise.bor(
Bitwise.bor(
# ??? - not documented in UC8159 datasheet
Bitwise.<<<(0x06, 3),
# SOURCE_INTERNAL_DC_DC
Bitwise.<<<(0x01, 2)
),
# GATE_INTERNAL_DC_DC
Bitwise.<<<(0x01, 1)
),
# LV_SOURCE_INTERNAL_DC_DC
0x01
),
# VGx_20V
0x00,
# UC8159_7C
0x23,
# UC8159_7C
0x23
])

# Set the PLL clock frequency to 50Hz
# 0b11000000 = Ignore
# 0b00111000 = M
# 0b00000111 = N
# PLL = 2MHz * (M / N)
# PLL = 2MHz * (7 / 4)
# PLL = 2,800,000 ???
defp set_pll_clock_frequency(state), do: write_command(state, 0x3C)

defp set_tse_register(state), do: write_command(state, 0x00)

defp set_vcom_data_interval_setting(state, border), do: write_command(state, @cdi, [Bitwise.bor(Bitwise.<<<(@colors[border], 5), 0x17)])
defp set_gate_source_non_overlap_period(state), do: write_command(state, @tcon, 0x22)
defp disable_external_flash(state), do: write_command(state, @dam, 0x00)
defp set_pws_whatever_that_means(state), do: write_command(state, @pws, 0xAA)
defp power_off_sequence(state), do: write_command(state, @pfs, 0x00)

defp set_analog_block_control(state), do: write_command(state, 0x74, 0x54)
defp set_digital_block_control(state), do: write_command(state, 0x7E, 0x3B)
defp set_gate(state, packed_height), do: write_command(state, 0x01, packed_height <> <<0x00>>)
Expand Down
46 changes: 3 additions & 43 deletions lib/hal/impression/rpiio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ defmodule Inky.Impression.RpiIO do
defstruct @state_fields
end

@colors %{
:black => 0,
:white => 1,
:green => 2,
:blue => 3,
:red => 4,
:yellow => 5,
:orange => 6,
:clean => 7
}

@default_palette = [
[57, 48, 57],
Expand All @@ -51,34 +41,6 @@ defmodule Inky.Impression.RpiIO do
@dc_pin 22
@cs0_pin 8

@psr 0x00
@pwr 0x01
@pof 0x02
@pfs 0x03
@pon 0x04
@btst 0x06
@dslp 0x07
@dtm1 0x10
@dsp 0x11
@drf 0x12
@ipc 0x13
@pll 0x30
@tsc 0x40
@tse 0x41
@tws 0x42
@tsr 0x43
@cdi 0x50
@lpd 0x51
@tcon 0x60
@tres 0x61
@dam 0x65
@rev 0x70
@flg 0x71
@amv 0x80
@vv 0x81
@vdcs 0x82
@pws 0xE3
@tsset 0xE5

@default_pin_mappings %{
busy_pin: @busy_pin,
Expand All @@ -87,7 +49,7 @@ defmodule Inky.Impression.RpiIO do
reset_pin: @reset_pin
}

@spi_speed_hz 488_000
@spi_speed_hz 3000000
Comment thread
jasonmj marked this conversation as resolved.
Outdated
@spi_command 0
@spi_data 1
@spi_chunk_size 4096
Expand All @@ -108,10 +70,8 @@ defmodule Inky.Impression.RpiIO do

spi_address = "spidev0." <> to_string(pin_mappings[:cs0_pin])

# TODO: Resume straight porting here, up to https://github.com/pimoroni/inky/blob/master/library/inky/inky_uc8159.py#L130

{:ok, dc_pid} = gpio.open(pin_mappings[:dc_pin], :output)
{:ok, reset_pid} = gpio.open(pin_mappings[:reset_pin], :output)
{:ok, dc_pid} = gpio.open(pin_mappings[:dc_pin], :output, initial_value: 0)
{:ok, reset_pid} = gpio.open(pin_mappings[:reset_pin], :output, initial_value: 1)
{:ok, busy_pid} = gpio.open(pin_mappings[:busy_pin], :input)
{:ok, spi_pid} = spi.open(spi_address, speed_hz: @spi_speed_hz)

Expand Down