€•ÎIŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ0/translations/zh_CN/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/zh_TW/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/it_IT/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/ja_JP/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/ko_KR/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/pt_BR/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/sp_SP/input/devices/rotary-encoder”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒ, Feb 2009 ”h]”hŒ paragraph”“”)”}”(hŒ'Daniel Mack , Feb 2009”h]”(hŒ Daniel Mack <”…””}”(hhíh²hh³Nh´NubhŒ reference”“”)”}”(hŒdaniel@caiaq.de”h]”hŒdaniel@caiaq.de”…””}”(hh÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:daniel@caiaq.de”uh1hõhhíubhŒ >, Feb 2009”…””}”(hhíh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khhçubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhÒubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÐh³hÊh´KhhÍh²hubah}”(h]”h ]”h"]”h$]”h&]”uh1hËhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒFunction”h]”hŒFunction”…””}”(hj&h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj#h²hh³hÊh´Kubhì)”}”(hŒàRotary encoders are devices which are connected to the CPU or other peripherals with two wires. The outputs are phase-shifted by 90 degrees and by triggering on falling and rising edges, the turn direction can be determined.”h]”hŒàRotary encoders are devices which are connected to the CPU or other peripherals with two wires. The outputs are phase-shifted by 90 degrees and by triggering on falling and rising edges, the turn direction can be determined.”…””}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K hj#h²hubhì)”}”(hŒÀSome encoders have both outputs low in stable states, others also have a stable state with both outputs high (half-period mode) and some have a stable state in all steps (quarter-period mode).”h]”hŒÀSome encoders have both outputs low in stable states, others also have a stable state with both outputs high (half-period mode) and some have a stable state in all steps (quarter-period mode).”…””}”(hjBh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khj#h²hubhì)”}”(hŒ7The phase diagram of these two outputs look like this::”h]”hŒ6The phase diagram of these two outputs look like this:”…””}”(hjPh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´Khj#h²hubhŒ literal_block”“”)”}”(hXx _____ _____ _____ | | | | | | Channel A ____| |_____| |_____| |____ : : : : : : : : : : : : __ _____ _____ _____ | | | | | | | Channel B |_____| |_____| |_____| |__ : : : : : : : : : : : : Event a b c d a b c d a b c d |<-------->| one step |<-->| one step (half-period mode) |<>| one step (quarter-period mode)”h]”hXx _____ _____ _____ | | | | | | Channel A ____| |_____| |_____| |____ : : : : : : : : : : : : __ _____ _____ _____ | | | | | | | Channel B |_____| |_____| |_____| |__ : : : : : : : : : : : : Event a b c d a b c d a b c d |<-------->| one step |<-->| one step (half-period mode) |<>| one step (quarter-period mode)”…””}”hj`sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j^h³hÊh´Khj#h²hubhŒdefinition_list”“”)”}”(hhh]”hŒdefinition_list_item”“”)”}”(hŒOFor more information, please see https://en.wikipedia.org/wiki/Rotary_encoder ”h]”(hŒterm”“”)”}”(hŒ For more information, please see”h]”hŒ For more information, please see”…””}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j{h³hÊh´K,hjwubhŒ definition”“”)”}”(hhh]”hì)”}”(hŒ,https://en.wikipedia.org/wiki/Rotary_encoder”h]”hö)”}”(hj’h]”hŒ,https://en.wikipedia.org/wiki/Rotary_encoder”…””}”(hj”h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j’uh1hõhjubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K+hjubah}”(h]”h ]”h"]”h$]”h&]”uh1j‹hjwubeh}”(h]”h ]”h"]”h$]”h&]”uh1juh³hÊh´K,hjrubah}”(h]”h ]”h"]”h$]”h&]”uh1jphj#h²hh³hÊh´Nubeh}”(h]”Œfunction”ah ]”h"]”Œfunction”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒEvents / state machine”h]”hŒEvents / state machine”…””}”(hjÅh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÂh²hh³hÊh´K/ubhì)”}”(hX In half-period mode, state a) and c) above are used to determine the rotational direction based on the last stable state. Events are reported in states b) and d) given that the new stable state is different from the last (i.e. the rotation was not reversed half-way).”h]”hX In half-period mode, state a) and c) above are used to determine the rotational direction based on the last stable state. Events are reported in states b) and d) given that the new stable state is different from the last (i.e. the rotation was not reversed half-way).”…””}”(hjÓh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K1hjÂh²hubhì)”}”(hŒOtherwise, the following apply:”h]”hŒOtherwise, the following apply:”…””}”(hjáh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K6hjÂh²hubhŒenumerated_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒgRising edge on channel A, channel B in low state This state is used to recognize a clockwise turn ”h]”jq)”}”(hhh]”jv)”}”(hŒbRising edge on channel A, channel B in low state This state is used to recognize a clockwise turn ”h]”(j|)”}”(hŒ0Rising edge on channel A, channel B in low state”h]”hŒ0Rising edge on channel A, channel B in low state”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j{h³hÊh´K9hjýubjŒ)”}”(hhh]”hì)”}”(hŒ0This state is used to recognize a clockwise turn”h]”hŒ0This state is used to recognize a clockwise turn”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K9hjubah}”(h]”h ]”h"]”h$]”h&]”uh1j‹hjýubeh}”(h]”h ]”h"]”h$]”h&]”uh1juh³hÊh´K9hjúubah}”(h]”h ]”h"]”h$]”h&]”uh1jphjöubah}”(h]”h ]”h"]”h$]”h&]”uh1jôhjñh²hh³Nh´Nubjõ)”}”(hŒÃRising edge on channel B, channel A in high state When entering this state, the encoder is put into 'armed' state, meaning that there it has seen half the way of a one-step transition. ”h]”jq)”}”(hhh]”jv)”}”(hŒ¹Rising edge on channel B, channel A in high state When entering this state, the encoder is put into 'armed' state, meaning that there it has seen half the way of a one-step transition. ”h]”(j|)”}”(hŒ1Rising edge on channel B, channel A in high state”h]”hŒ1Rising edge on channel B, channel A in high state”…””}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j{h³hÊh´K=hj?ubjŒ)”}”(hhh]”hì)”}”(hŒ†When entering this state, the encoder is put into 'armed' state, meaning that there it has seen half the way of a one-step transition.”h]”hŒŠWhen entering this state, the encoder is put into ‘armed’ state, meaning that there it has seen half the way of a one-step transition.”…””}”(hjTh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K #include #include #define GPIO_ROTARY_A 1 #define GPIO_ROTARY_B 2 static struct gpiod_lookup_table rotary_encoder_gpios = { .dev_id = "rotary-encoder.0", .table = { GPIO_LOOKUP_IDX("gpio-0", GPIO_ROTARY_A, NULL, 0, GPIO_ACTIVE_LOW), GPIO_LOOKUP_IDX("gpio-0", GPIO_ROTARY_B, NULL, 1, GPIO_ACTIVE_HIGH), { }, }, }; static const struct property_entry rotary_encoder_properties[] = { PROPERTY_ENTRY_U32("rotary-encoder,steps-per-period", 24), PROPERTY_ENTRY_U32("linux,axis", ABS_X), PROPERTY_ENTRY_U32("rotary-encoder,relative_axis", 0), { }, }; static const struct software_node rotary_encoder_node = { .properties = rotary_encoder_properties, }; static struct platform_device rotary_encoder_device = { .name = "rotary-encoder", .id = 0, }; ... gpiod_add_lookup_table(&rotary_encoder_gpios); device_add_software_node(&rotary_encoder_device.dev, &rotary_encoder_node); platform_device_register(&rotary_encoder_device); ...”h]”hXò/* board support file example */ #include #include #include #define GPIO_ROTARY_A 1 #define GPIO_ROTARY_B 2 static struct gpiod_lookup_table rotary_encoder_gpios = { .dev_id = "rotary-encoder.0", .table = { GPIO_LOOKUP_IDX("gpio-0", GPIO_ROTARY_A, NULL, 0, GPIO_ACTIVE_LOW), GPIO_LOOKUP_IDX("gpio-0", GPIO_ROTARY_B, NULL, 1, GPIO_ACTIVE_HIGH), { }, }, }; static const struct property_entry rotary_encoder_properties[] = { PROPERTY_ENTRY_U32("rotary-encoder,steps-per-period", 24), PROPERTY_ENTRY_U32("linux,axis", ABS_X), PROPERTY_ENTRY_U32("rotary-encoder,relative_axis", 0), { }, }; static const struct software_node rotary_encoder_node = { .properties = rotary_encoder_properties, }; static struct platform_device rotary_encoder_device = { .name = "rotary-encoder", .id = 0, }; ... gpiod_add_lookup_table(&rotary_encoder_gpios); device_add_software_node(&rotary_encoder_device.dev, &rotary_encoder_node); platform_device_register(&rotary_encoder_device); ...”…””}”hjWsbah}”(h]”h ]”h"]”h$]”h&]”jnjouh1j^h³hÊh´KZhj8h²hubhì)”}”(hŒ_Please consult device tree binding documentation to see all properties supported by the driver.”h]”hŒ_Please consult device tree binding documentation to see all properties supported by the driver.”…””}”(hjeh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÊh´K†hj8h²hubeh}”(h]”Œboard-integration”ah ]”h"]”Œboard integration”ah$]”h&]”uh1hµhh·h²hh³hÊh´KPubeh}”(h]”Œ:rotary-encoder-a-generic-driver-for-gpio-connected-devices”ah ]”h"]”Œ