Class: AVR::RegisterWithBitNumber
- Extended by:
- T::Sig
- Defined in:
- lib/avr/register_with_bit_number.rb
Instance Attribute Summary collapse
-
#bit_mask ⇒ Object
readonly
Returns the value of attribute bit_mask.
-
#bit_number ⇒ Object
readonly
Returns the value of attribute bit_number.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
Instance Method Summary collapse
-
#initialize(register, bit_number) ⇒ RegisterWithBitNumber
constructor
A new instance of RegisterWithBitNumber.
- #name ⇒ Object
- #value ⇒ Object
- #value=(new_value) ⇒ Object
Methods inherited from Value
#format, #inspect, #to_i, #to_s, #value_hex
Constructor Details
#initialize(register, bit_number) ⇒ RegisterWithBitNumber
Returns a new instance of RegisterWithBitNumber.
18 19 20 21 22 23 |
# File 'lib/avr/register_with_bit_number.rb', line 18 def initialize(register, bit_number) @register = register @bit_number = bit_number @bit_mask = T.let(1<<bit_number, Integer) super() end |
Instance Attribute Details
#bit_mask ⇒ Object (readonly)
Returns the value of attribute bit_mask.
15 16 17 |
# File 'lib/avr/register_with_bit_number.rb', line 15 def bit_mask @bit_mask end |
#bit_number ⇒ Object (readonly)
Returns the value of attribute bit_number.
12 13 14 |
# File 'lib/avr/register_with_bit_number.rb', line 12 def bit_number @bit_number end |
#register ⇒ Object (readonly)
Returns the value of attribute register.
9 10 11 |
# File 'lib/avr/register_with_bit_number.rb', line 9 def register @register end |
Instance Method Details
#name ⇒ Object
36 37 38 |
# File 'lib/avr/register_with_bit_number.rb', line 36 def name "#{register.name}.#{bit_number}" end |
#value ⇒ Object
26 27 28 |
# File 'lib/avr/register_with_bit_number.rb', line 26 def value (register.value & bit_mask) >> bit_number end |
#value=(new_value) ⇒ Object
31 32 33 |
# File 'lib/avr/register_with_bit_number.rb', line 31 def value=(new_value) register.value |= (new_value << bit_number) & bit_mask end |