Hitachi HD44780 or similar 2-4 lines LCD displays

Introduced properties

fun clear

bcm2835 :: HD44780 :: clear

fun d4: RPiPin

bcm2835 :: HD44780 :: d4

protected fun d4=(d4: RPiPin)

bcm2835 :: HD44780 :: d4=

fun d5: RPiPin

bcm2835 :: HD44780 :: d5

protected fun d5=(d5: RPiPin)

bcm2835 :: HD44780 :: d5=

fun d6: RPiPin

bcm2835 :: HD44780 :: d6

protected fun d6=(d6: RPiPin)

bcm2835 :: HD44780 :: d6=

fun d7: RPiPin

bcm2835 :: HD44780 :: d7

protected fun d7=(d7: RPiPin)

bcm2835 :: HD44780 :: d7=

init defaultinit(rs: RPiPin, en: RPiPin, d4: RPiPin, d5: RPiPin, d6: RPiPin, d7: RPiPin)

bcm2835 :: HD44780 :: defaultinit

fun display_control(on: Bool, cursor: Bool, blink: Bool)

bcm2835 :: HD44780 :: display_control

fun ds: Array[RPiPin]

bcm2835 :: HD44780 :: ds

protected fun ds=(ds: Array[RPiPin])

bcm2835 :: HD44780 :: ds=

fun en: RPiPin

bcm2835 :: HD44780 :: en

protected fun en=(en: RPiPin)

bcm2835 :: HD44780 :: en=

fun entry_mode(left: Bool, incr: Bool)

bcm2835 :: HD44780 :: entry_mode

fun flag_8bit_mode: Int

bcm2835 :: HD44780 :: flag_8bit_mode

function set
fun flag_display_move: Int

bcm2835 :: HD44780 :: flag_display_move

display/cursor shift
fun flag_display_on: Int

bcm2835 :: HD44780 :: flag_display_on

display flags
fun function_set(bits: Int, lines: Int, dots_wide: Int)

bcm2835 :: HD44780 :: function_set

fun rs: RPiPin

bcm2835 :: HD44780 :: rs

protected fun rs=(rs: RPiPin)

bcm2835 :: HD44780 :: rs=

fun setup

bcm2835 :: HD44780 :: setup

fun text=(v: String)

bcm2835 :: HD44780 :: text=

fun write(is_cmd: Bool, cmd: Int)

bcm2835 :: HD44780 :: write

fun write_4bits(a: Bool, b: Bool, c: Bool, d: Bool)

bcm2835 :: HD44780 :: write_4bits

Redefined properties

redef type SELF: HD44780

bcm2835 $ HD44780 :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun clear

bcm2835 :: HD44780 :: clear

fun d4: RPiPin

bcm2835 :: HD44780 :: d4

protected fun d4=(d4: RPiPin)

bcm2835 :: HD44780 :: d4=

fun d5: RPiPin

bcm2835 :: HD44780 :: d5

protected fun d5=(d5: RPiPin)

bcm2835 :: HD44780 :: d5=

fun d6: RPiPin

bcm2835 :: HD44780 :: d6

protected fun d6=(d6: RPiPin)

bcm2835 :: HD44780 :: d6=

fun d7: RPiPin

bcm2835 :: HD44780 :: d7

protected fun d7=(d7: RPiPin)

bcm2835 :: HD44780 :: d7=

init defaultinit(rs: RPiPin, en: RPiPin, d4: RPiPin, d5: RPiPin, d6: RPiPin, d7: RPiPin)

bcm2835 :: HD44780 :: defaultinit

fun display_control(on: Bool, cursor: Bool, blink: Bool)

bcm2835 :: HD44780 :: display_control

fun ds: Array[RPiPin]

bcm2835 :: HD44780 :: ds

protected fun ds=(ds: Array[RPiPin])

bcm2835 :: HD44780 :: ds=

fun en: RPiPin

bcm2835 :: HD44780 :: en

protected fun en=(en: RPiPin)

bcm2835 :: HD44780 :: en=

fun entry_mode(left: Bool, incr: Bool)

bcm2835 :: HD44780 :: entry_mode

fun flag_8bit_mode: Int

bcm2835 :: HD44780 :: flag_8bit_mode

function set
fun flag_display_move: Int

bcm2835 :: HD44780 :: flag_display_move

display/cursor shift
fun flag_display_on: Int

bcm2835 :: HD44780 :: flag_display_on

display flags
fun function_set(bits: Int, lines: Int, dots_wide: Int)

bcm2835 :: HD44780 :: function_set

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun rs: RPiPin

bcm2835 :: HD44780 :: rs

protected fun rs=(rs: RPiPin)

bcm2835 :: HD44780 :: rs=

fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun setup

bcm2835 :: HD44780 :: setup

intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun text=(v: String)

bcm2835 :: HD44780 :: text=

abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun write(is_cmd: Bool, cmd: Int)

bcm2835 :: HD44780 :: write

fun write_4bits(a: Bool, b: Bool, c: Bool, d: Bool)

bcm2835 :: HD44780 :: write_4bits

package_diagram bcm2835::HD44780 HD44780 core::Object Object bcm2835::HD44780->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

bcm2835 $ HD44780
# Hitachi HD44780 or similar 2-4 lines LCD displays
class HD44780
	var rs: RPiPin
	var en: RPiPin
	var d4: RPiPin
	var d5: RPiPin
	var d6: RPiPin
	var d7: RPiPin

	var ds = new Array[RPiPin]

	# commands
	fun flag_clear_display: Int do return 1
	fun flag_return_home: Int do return 2
	fun flag_entry_mode_set: Int do return 4
	fun flag_display_control: Int do return 8
	fun flag_cursor_shift: Int do return 16
	fun flag_function_set: Int do return 32
	fun flag_set_cgram_addr: Int do return 64
	fun flag_set_ggram_addr: Int do return 128

	# entry mode
	fun flag_entry_right: Int do return 0
	fun flag_entry_left: Int do return 2
	fun flag_entry_shift_increment: Int do return 1
	fun flag_entry_shift_decrement: Int do return 0

	# display flags
	fun flag_display_on: Int do return 4
	fun flag_display_off: Int do return 0
	fun flag_cursor_on: Int do return 2
	fun flag_cursor_off: Int do return 0
	fun flag_blink_on: Int do return 1
	fun flag_blink_off: Int do return 0

	# display/cursor shift
	fun flag_display_move: Int do return 8
	fun flag_cursor_move: Int do return 0
	fun flag_move_right: Int do return 4
	fun flag_move_left: Int do return 0

	# function set
	fun flag_8bit_mode: Int do return 16
	fun flag_4bit_mode: Int do return 0
	fun flag_2_lines: Int do return 8
	fun flag_1_line: Int do return 0
	fun flag_5x10_dots: Int do return 4
	fun flag_5x8_dots: Int do return 0

	# last text displayed
	private var last_text: nullable String = null

	fun function_set(bits, lines, dots_wide: Int)
	do
		var fs = flag_function_set
		if bits == 8 then
			fs = fs | 16
		else if bits != 4 then abort

		if lines == 2 then
			fs = fs | 8
		else if lines != 1 then abort

		if dots_wide == 10 then
			fs = fs | 4
		else if dots_wide != 8 then abort

		write(true, fs)
	end

	fun display_control(on, cursor, blink: Bool)
	do
		var fs = flag_display_control

		fs |= if on then flag_display_on else flag_display_off

		fs |= if cursor then flag_cursor_on else flag_cursor_off

		fs |= if blink then flag_blink_on else flag_blink_off

		write(true, fs)
	end

	fun entry_mode(left, incr: Bool)
	do
		var fs = flag_entry_mode_set

		fs |= if left then flag_entry_left else flag_entry_right

		fs |= if incr then flag_entry_shift_increment else flag_entry_shift_decrement

		write(true, fs)
	end

	fun setup_alt
	do
		ds = [d4,d5,d6,d7]

		rs.fsel = new FunctionSelect.outp
		en.fsel = new FunctionSelect.outp
		d4.fsel = new FunctionSelect.outp
		d5.fsel = new FunctionSelect.outp
		d6.fsel = new FunctionSelect.outp
		d7.fsel = new FunctionSelect.outp

		rs.write(false)
		en.write(false)

		# wait 20ms for power up
		50.bcm2835_delay

		write_4bits(true,true,false,false)
		write_4_bits(3)

		5.bcm2835_delay

		write_4bits(true,true,false,false)
		write_4_bits(3)

		5.bcm2835_delay

		write_4bits(true,true,false,false)
		write_4_bits(3)

		200.bcm2835_delay_micros

		write_4bits(false,true,false,false)
		write_4_bits(2)

		# wait 5ms
		5.bcm2835_delay

		# set interface
		# 4bits, 2 lines
		function_set(4, 2, 8)

		# cursor
		# don't shift & hide
		display_control(true, true, true)

		# clear & home
		clear

		# set cursor move direction
		# move right
		write(true, 6)

		# turn on display
		write(true, 4)

		# set entry mode
		entry_mode(true, true)
	end

	fun setup
	do
		ds = [d4,d5,d6,d7]

		rs.fsel = new FunctionSelect.outp
		en.fsel = new FunctionSelect.outp
		d4.fsel = new FunctionSelect.outp
		d5.fsel = new FunctionSelect.outp
		d6.fsel = new FunctionSelect.outp
		d7.fsel = new FunctionSelect.outp

		rs.write(false)
		en.write(false)

		write(true, "33".to_hex) # init
		write(true, "32".to_hex) # init
		write(true, "28".to_hex) # 2 lines, 5x7
		write(true, "0C".to_hex) # hide cursor
		write(true, "06".to_hex) # cursor move right
		write(true, "04".to_hex) # turn on display
		write(true, "01".to_hex) # clear display
	end

	fun write_4_bits(v: Int)
	do
		var lb = once [1,2,4,8]
		for i in [0..4[ do
			var b = lb[i]
			var r = b & v != 0
			var d = ds[i]
			d.write(r)
		end
		pulse_enable
	end

	fun write_4bits(a,b,c,d:Bool)
	do
		d4.write(a)
		d5.write(b)
		d6.write(c)
		d7.write(d)
		pulse_enable
	end

	fun pulse_enable
	do
		en.write(false)
		1.bcm2835_delay_micros
		en.write(true)
		100.bcm2835_delay_micros
		en.write(false)
		1.bcm2835_delay_micros
	end

	fun write(is_cmd: Bool, cmd: Int)
	do
		en.write(false)
		rs.write(not is_cmd)

		# high byte
		var hb = once [16,32,64,128]
		for i in [0..4[ do
			var b = hb[i]
			var r = b & cmd != 0
			var d = ds[i]
			d.write(r)
		end

		pulse_enable

		if is_cmd then
			# wait 5ms
			5.bcm2835_delay
		else
			# wait 200us
			200.bcm2835_delay_micros
		end

		# low byte
		var lb = once [1,2,4,8]
		for i in [0..4[ do
			var b = lb[i]
			var r = b & cmd != 0
			var d = ds[i]
			d.write(r)
		end

		pulse_enable

		if is_cmd then
			# wait 5ms
			5.bcm2835_delay
		else
			# wait 200us
			200.bcm2835_delay_micros
		end
	end

	fun clear
	do
		write(true,1)
		2.bcm2835_delay
	end

	fun return_home
	do
		write(true,2)
		2.bcm2835_delay
	end

	fun text=(v: String)
	do
		# do not redraw the samething
		var last_text = last_text
		if last_text != null and last_text == v then return

		clear
		return_home
		var count = 0
		for c in v.chars do
			if c == '\n' then
				# FIXME, this should work
				#write(true, "C0".to_hex)
				# instead we use the following which may not be portable

				for s in [count..40[ do write(false, ' '.code_point)
				count = 0
			else
				write(false, c.code_point)
				count += 1
			end
		end

		self.last_text = v
	end
end
lib/bcm2835/bcm2835.nit:164,1--453,3