diff --git a/src/Makefile b/src/Makefile index 3ea9c78..d379b88 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ CMSIS_DIR = ../CMSIS_5/CMSIS OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \ mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \ sysexfileloader.o performanceconfig.o perftimer.o \ - effect_compressor.o effect_platervbstereo.o + effect_compressor.o effect_platervbstereo.o uibuttons.o OPTIMIZE = -O3 diff --git a/src/config.cpp b/src/config.cpp index fe8095a..c96c450 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -81,12 +81,12 @@ void CConfig::Load (void) m_nLCDPinData7 = m_Properties.GetNumber ("LCDPinData7", 25); m_nLCDI2CAddress = m_Properties.GetNumber ("LCDI2CAddress", 0); - m_bBTNEnabled = m_Properties.GetNumber ("BTNEnabled", 0) != 0; - m_nBTNPinLeft = m_Properties.GetNumber ("BTNPinLeft", 5); - m_nBTNPinRight = m_Properties.GetNumber ("BTNPinRight", 6); - m_nBTNPinUp = m_Properties.GetNumber ("BTNPinUp", 10); - m_nBTNPinDown = m_Properties.GetNumber ("BTNPinDown", 9); - m_nBTNPinSelect = m_Properties.GetNumber ("BTNPinSelect", 11); + m_bButtonEnabled = m_Properties.GetNumber ("ButtonEnabled", 0) != 0; + m_nButtonPinPrev = m_Properties.GetNumber ("ButtonPinPrev", NOPIN); + m_nButtonPinNext = m_Properties.GetNumber ("ButtonPinNext", NOPIN); + m_nButtonPinBack = m_Properties.GetNumber ("ButtonPinBack", NOPIN); + m_nButtonPinSelect = m_Properties.GetNumber ("ButtonPinSelect", NOPIN); + m_nButtonPinHome = m_Properties.GetNumber ("ButtonPinHome", NOPIN); m_bEncoderEnabled = m_Properties.GetNumber ("EncoderEnabled", 0) != 0; m_nEncoderPinClock = m_Properties.GetNumber ("EncoderPinClock", 10); @@ -187,34 +187,34 @@ unsigned CConfig::GetLCDI2CAddress (void) const return m_nLCDI2CAddress; } -bool CConfig::GetBTNEnabled (void) const +bool CConfig::GetButtonEnabled (void) const { - return m_bBTNEnabled; + return m_bButtonEnabled; } -unsigned CConfig::GetBTNPinLeft (void) const +unsigned CConfig::GetButtonPinPrev (void) const { - return m_nBTNPinLeft; + return m_nButtonPinPrev; } -unsigned CConfig::GetBTNPinRight (void) const +unsigned CConfig::GetButtonPinNext (void) const { - return m_nBTNPinRight; + return m_nButtonPinNext; } -unsigned CConfig::GetBTNPinUp (void) const +unsigned CConfig::GetButtonPinBack (void) const { - return m_nBTNPinUp; + return m_nButtonPinBack; } -unsigned CConfig::GetBTNPinDown (void) const +unsigned CConfig::GetButtonPinSelect (void) const { - return m_nBTNPinDown; + return m_nButtonPinSelect; } -unsigned CConfig::GetBTNPinSelect (void) const +unsigned CConfig::GetButtonPinHome (void) const { - return m_nBTNPinSelect; + return m_nButtonPinHome; } bool CConfig::GetEncoderEnabled (void) const diff --git a/src/config.h b/src/config.h index 780681a..7b7cbdf 100644 --- a/src/config.h +++ b/src/config.h @@ -28,6 +28,9 @@ #include #include +// This has to match the value mentioned in minidexed.ini +#define NOPIN 255 + class CConfig // Configuration for MiniDexed { public: @@ -90,12 +93,12 @@ public: // GPIO Button Navigation // GPIO pin numbers are chip numbers, not header positions - bool GetBTNEnabled (void) const; - unsigned GetBTNPinLeft (void) const; - unsigned GetBTNPinRight (void) const; - unsigned GetBTNPinUp (void) const; - unsigned GetBTNPinDown (void) const; - unsigned GetBTNPinSelect (void) const; + bool GetButtonEnabled (void) const; + unsigned GetButtonPinPrev (void) const; + unsigned GetButtonPinNext (void) const; + unsigned GetButtonPinBack (void) const; + unsigned GetButtonPinSelect (void) const; + unsigned GetButtonPinHome (void) const; // KY-040 Rotary Encoder // GPIO pin numbers are chip numbers, not header positions @@ -132,12 +135,12 @@ private: unsigned m_nLCDPinData7; unsigned m_nLCDI2CAddress; - bool m_bBTNEnabled; - unsigned m_nBTNPinLeft; - unsigned m_nBTNPinRight; - unsigned m_nBTNPinUp; - unsigned m_nBTNPinDown; - unsigned m_nBTNPinSelect; + bool m_bButtonEnabled; + unsigned m_nButtonPinPrev; + unsigned m_nButtonPinNext; + unsigned m_nButtonPinBack; + unsigned m_nButtonPinSelect; + unsigned m_nButtonPinHome; bool m_bEncoderEnabled; unsigned m_nEncoderPinClock; diff --git a/src/minidexed.ini b/src/minidexed.ini index 51ebf8e..74a6f4d 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -28,15 +28,21 @@ LCDPinData7=25 LCDI2CAddress=0x00 # GPIO Button Navigation -BTNEnabled=1 -BTNPinLeft=5 -BTNPinRight=6 -BTNPinUp=16 -BTNPinDown=20 -BTNPinSelect=12 +# There are two suggested button schemes: +# 5 Buttons based on an "arrow keypad" with a "home" +# 2 Buttons "back" and "select" for use in addition to a rotary encoder +# +# Although actually any buttons set to 255 will be ignored +# +ButtonEnabled=1 +ButtonPinPrev=16 +ButtonPinNext=20 +ButtonPinBack=5 +ButtonPinSelect=6 +ButtonPinHome=12 # KY-040 Rotary Encoder -EncoderEnabled=0 +EncoderEnabled=1 EncoderPinClock=10 EncoderPinData=9 EncoderPinSwitch=11 diff --git a/src/uibuttons.cpp b/src/uibuttons.cpp index f8b7d9a..6a5850b 100644 --- a/src/uibuttons.cpp +++ b/src/uibuttons.cpp @@ -27,17 +27,28 @@ LOGMODULE ("uibuttons"); CUIButton::CUIButton (unsigned nPin) -: m_Pin (nPin, GPIOModeInputPullUp), +: m_nPin (nPin), + m_pPin (0), m_nLastValue (0) { } CUIButton::~CUIButton (void) { + if (m_pPin) + { + delete m_pPin; + } } boolean CUIButton::Initialize (void) { + assert (!m_pPin); + + if (m_nPin != NOPIN) + { + m_pPin = new CGPIOPin (m_nPin, GPIOModeInputPullUp); + } return TRUE; } @@ -45,9 +56,16 @@ boolean CUIButton::Initialize (void) boolean CUIButton::Read (void) { - unsigned nValue = m_Pin.Read(); + if (!m_pPin) + { + // Always return "not pressed" if not configured + return FALSE; + } + + unsigned nValue = m_pPin->Read(); - if (nValue != 0) + // Buttons in PULL UP mode are "active low" + if (nValue == 0) { // Some simple debouncing... if (m_nLastValue < DEBOUNCER) @@ -73,12 +91,12 @@ boolean CUIButton::Read (void) } -CUIButtons::CUIButtons (unsigned nLeftPin, unsigned nRightPin, unsigned nUpPin, unsigned nDownPin, unsigned nSelectPin) -: m_LeftButton (nLeftPin), - m_RightButton (nRightPin), - m_UpButton (nUpPin), - m_DownButton (nDownPin), - m_SelectButton (nSelectPin) +CUIButtons::CUIButtons (unsigned nPrevPin, unsigned nNextPin, unsigned nBackPin, unsigned nSelectPin, unsigned nHomePin) +: m_PrevButton (nPrevPin), + m_NextButton (nNextPin), + m_BackButton (nBackPin), + m_SelectButton (nSelectPin), + m_HomeButton (nHomePin) { } @@ -88,6 +106,12 @@ CUIButtons::~CUIButtons (void) boolean CUIButtons::Initialize (void) { + m_PrevButton.Initialize (); + m_NextButton.Initialize (); + m_BackButton.Initialize (); + m_SelectButton.Initialize (); + m_HomeButton.Initialize (); + return TRUE; } @@ -103,30 +127,30 @@ void CUIButtons::Update (void) { assert (m_pEventHandler); - if (m_LeftButton.Read ()) - { - LOGNOTE ("Left"); - (*m_pEventHandler) (BtnEventLeft, m_pEventParam); - } - if (m_RightButton.Read ()) + if (m_PrevButton.Read ()) { - LOGNOTE ("Right"); - (*m_pEventHandler) (BtnEventRight, m_pEventParam); + LOGDBG ("Prev"); + (*m_pEventHandler) (BtnEventPrev, m_pEventParam); } - if (m_UpButton.Read ()) + if (m_NextButton.Read ()) { - LOGNOTE ("Up"); - (*m_pEventHandler) (BtnEventUp, m_pEventParam); + LOGDBG ("Next"); + (*m_pEventHandler) (BtnEventNext, m_pEventParam); } - if (m_DownButton.Read ()) + if (m_BackButton.Read ()) { - LOGNOTE ("Down"); - (*m_pEventHandler) (BtnEventDown, m_pEventParam); + LOGDBG ("Back"); + (*m_pEventHandler) (BtnEventBack, m_pEventParam); } if (m_SelectButton.Read ()) { - LOGNOTE ("Select"); + LOGDBG ("Select"); (*m_pEventHandler) (BtnEventSelect, m_pEventParam); } + if (m_HomeButton.Read ()) + { + LOGDBG ("Home"); + (*m_pEventHandler) (BtnEventHome, m_pEventParam); + } } diff --git a/src/uibuttons.h b/src/uibuttons.h index bfaf75c..5870ec3 100644 --- a/src/uibuttons.h +++ b/src/uibuttons.h @@ -38,28 +38,28 @@ public: boolean Read (void); private: - CGPIOPin m_Pin; + unsigned m_nPin; + CGPIOPin *m_pPin; unsigned m_nLastValue; }; - class CUIButtons { public: enum TBtnEvent { - BtnEventLeft, - BtnEventRight, - BtnEventUp, - BtnEventDown, + BtnEventPrev, + BtnEventNext, + BtnEventBack, BtnEventSelect, + BtnEventHome, BtnEventUnknown }; typedef void TBtnEventHandler (TBtnEvent Event, void *pParam); public: - CUIButtons (unsigned nLeftPin, unsigned nRightPin, unsigned nUpPin, unsigned nDownPin, unsigned nSelectPin); + CUIButtons (unsigned nPrevPin = NOPIN, unsigned nNextPin = NOPIN, unsigned nBackPin = NOPIN, unsigned nSelectPin = NOPIN, unsigned nHomePin = NOPIN); ~CUIButtons (void); boolean Initialize (void); @@ -69,11 +69,11 @@ public: void Update (void); private: - CUIButton m_LeftButton; - CUIButton m_RightButton; - CUIButton m_UpButton; - CUIButton m_DownButton; + CUIButton m_PrevButton; + CUIButton m_NextButton; + CUIButton m_BackButton; CUIButton m_SelectButton; + CUIButton m_HomeButton; TBtnEventHandler *m_pEventHandler; void *m_pEventParam; diff --git a/src/userinterface.cpp b/src/userinterface.cpp index 1e19605..3e25426 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -87,13 +87,13 @@ bool CUserInterface::Initialize (void) LOGDBG ("LCD initialized"); } - if (m_pConfig->GetBTNEnabled ()) + if (m_pConfig->GetButtonEnabled ()) { - m_pUIButtons = new CUIButtons (m_pConfig->GetBTNPinLeft (), - m_pConfig->GetBTNPinRight (), - m_pConfig->GetBTNPinUp (), - m_pConfig->GetBTNPinDown (), - m_pConfig->GetBTNPinSelect ()); + m_pUIButtons = new CUIButtons ( m_pConfig->GetButtonPinPrev (), + m_pConfig->GetButtonPinNext (), + m_pConfig->GetButtonPinBack (), + m_pConfig->GetButtonPinSelect (), + m_pConfig->GetButtonPinHome ()); assert (m_pUIButtons); if (!m_pUIButtons->Initialize ()) @@ -269,23 +269,23 @@ void CUserInterface::UIButtonsEventHandler (CUIButtons::TBtnEvent Event) { switch (Event) { - case CUIButtons::BtnEventUp: - m_Menu.EventHandler (CUIMenu::MenuEventStepUp); + case CUIButtons::BtnEventPrev: + m_Menu.EventHandler (CUIMenu::MenuEventStepDown); break; - case CUIButtons::BtnEventDown: - m_Menu.EventHandler (CUIMenu::MenuEventStepDown); + case CUIButtons::BtnEventNext: + m_Menu.EventHandler (CUIMenu::MenuEventStepUp); break; - case CUIButtons::BtnEventLeft: + case CUIButtons::BtnEventBack: m_Menu.EventHandler (CUIMenu::MenuEventBack); break; - case CUIButtons::BtnEventRight: + case CUIButtons::BtnEventSelect: m_Menu.EventHandler (CUIMenu::MenuEventSelect); break; - case CUIButtons::BtnEventSelect: + case CUIButtons::BtnEventHome: m_Menu.EventHandler (CUIMenu::MenuEventHome); break;