€•òHŒ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Œ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”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjhž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.”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h K hjhž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).”…””}”(hj.hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h KhjhžhubhØ)”}”(hŒ7The phase diagram of these two outputs look like this::”h]”hŒ6The phase diagram of these two outputs look like this:”…””}”(hj<hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h Khjhž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)”…””}”hjLsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jJhŸh¶h Khjhž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”…””}”(hjihžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jghŸh¶h K,hjcubhŒ 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áhj|ubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h K+hjyubah}”(h]”h ]”h"]”h$]”h&]”uh1jwhjcubeh}”(h]”h ]”h"]”h$]”h&]”uh1jahŸh¶h K,hj^ubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjhž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]”j])”}”(hhh]”jb)”}”(hŒbRising edge on channel A, channel B in low state This state is used to recognize a clockwise turn ”h]”(jh)”}”(hŒ0Rising edge on channel A, channel B in low state”h]”hŒ0Rising edge on channel A, channel B in low state”…””}”(hjíhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jghŸh¶h K9hjéubjx)”}”(hhh]”hØ)”}”(hŒ0This state is used to recognize a clockwise turn”h]”hŒ0This state is used to recognize a clockwise turn”…””}”(hjþhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h K9hjûubah}”(h]”h ]”h"]”h$]”h&]”uh1jwhjéubeh}”(h]”h ]”h"]”h$]”h&]”uh1jahŸh¶h K9hjæubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjâ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]”j])”}”(hhh]”jb)”}”(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]”(jh)”}”(hŒ1Rising edge on channel B, channel A in high state”h]”hŒ1Rising edge on channel B, channel A in high state”…””}”(hj/hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jghŸh¶h K=hj+ubjx)”}”(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.”…””}”(hj@hž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); ...”…””}”hjCsbah}”(h]”h ]”h"]”h$]”h&]”jZj[uh1jJhŸh¶h KZhj$hž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.”…””}”(hjQhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh¶h K†hj$hž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"]”Œ