Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic STM32 adaptation #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 16 additions & 4 deletions ClickEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@
// ----------------------------------------------------------------------------

ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
: doubleClickEnabled(true), accelerationEnabled(true),
delta(0), last(0), acceleration(0),
button(Open), steps(stepsPerNotch),
pinA(A), pinB(B), pinBTN(BTN), pinsActive(active)
:
pinA(A), pinB(B), pinBTN(BTN), pinsActive(active),
delta(0), last(0),
steps(stepsPerNotch),
acceleration(0),
accelerationEnabled(true),
button(Open),
doubleClickEnabled(true)
{
#ifndef ARDUINO_ARCH_STM32
uint8_t configType = (pinsActive == LOW) ? INPUT_PULLUP : INPUT;
#else
WiringPinMode configType = (pinsActive == LOW) ? INPUT_PULLUP : INPUT;
#endif
pinMode(pinA, configType);
pinMode(pinB, configType);
pinMode(pinBTN, configType);
Expand Down Expand Up @@ -178,14 +186,18 @@ int16_t ClickEncoder::getValue(void)
{
int16_t val;

#ifndef ARDUINO_ARCH_STM32
cli();
#endif
val = delta;

if (steps == 2) delta = val & 1;
else if (steps == 4) delta = val & 3;
else delta = 0; // default to 1 step per notch

#ifndef ARDUINO_ARCH_STM32
sei();
#endif

if (steps == 4) val >>= 2;
if (steps == 2) val >>= 1;
Expand Down
2 changes: 2 additions & 0 deletions ClickEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// ----------------------------------------------------------------------------

#include <stdint.h>
#ifdef __AVR__
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#endif
#include "Arduino.h"

// ----------------------------------------------------------------------------
Expand Down