A lot of renaming, refactoring and updating of code
This commit is contained in:
@@ -7,3 +7,12 @@
|
||||
[submodule "libs/aconnoNordicPAL"]
|
||||
path = libs/aconnoNordicPAL
|
||||
url = https://git.simvelop.de/aconnoLibs/aconnoNordicPAL
|
||||
[submodule "libs/GDEP015OC1"]
|
||||
path = libs/GDEP015OC1
|
||||
url = https://git.simvelop.de/aconnoLibs/GDEP015OC1.git
|
||||
[submodule "libs/aconnoSPI"]
|
||||
path = libs/aconnoSPI
|
||||
url = https://git.simvelop.de/aconnoLibs/aconnoSPI.git
|
||||
[submodule "libs/aconnoI2C"]
|
||||
path = libs/aconnoI2C
|
||||
url = https://git.simvelop.de/aconnoLibs/aconnoI2C.git
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "MCP23017.h"
|
||||
|
||||
|
||||
/**@brief Function for the Timer initialization.
|
||||
*
|
||||
* @details Initializes the timer module. This creates and starts application timers.
|
||||
@@ -129,4 +132,17 @@ void logState(TaskHandle_t xCreatedTask)
|
||||
NRF_LOG_INFO("Task Suspended");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initIoExpander(MCP23017* expdr)
|
||||
{
|
||||
expdr->reset();
|
||||
expdr->config(0x01F8, 0xFFFF, 0x0000);
|
||||
|
||||
for(uint8_t x=3; x<10; x++) // Init values on Expander pins
|
||||
{
|
||||
expdr->writeGPIOBit(1, x);
|
||||
}
|
||||
expdr->writeGPIOBit(0, 10);
|
||||
expdr->writeGPIOBit(0, 11);
|
||||
}
|
||||
|
||||
@@ -15,19 +15,25 @@
|
||||
#include <stdint.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "MCP23017.h"
|
||||
|
||||
/**
|
||||
* @brief Enumeration for the button pressed
|
||||
* @brief Enumeration for the interrupt source pressed
|
||||
*
|
||||
*/
|
||||
enum BTN_PRESSED : uint8_t
|
||||
enum IOEXP_INT_SOURCE : uint8_t
|
||||
{
|
||||
|
||||
NOTHING = 0,
|
||||
UP = 1,
|
||||
RIGHT = 2,
|
||||
DOWN = 3,
|
||||
LEFT = 4,
|
||||
CENTER = 5
|
||||
JOY_UP = 6,
|
||||
JOY_RIGHT = 3,
|
||||
JOY_DOWN = 4,
|
||||
JOY_LEFT = 5,
|
||||
JOY_CENTER = 7,
|
||||
SW2 = 8,
|
||||
LED2 = 9,
|
||||
REL1 = 11,
|
||||
REL2 = 10
|
||||
};
|
||||
|
||||
void timers_init(void);
|
||||
@@ -55,6 +61,14 @@ BaseType_t xTaskCreateOrResume(TaskFunction_t pvTaskCode,
|
||||
*/
|
||||
void logState(TaskHandle_t xCreatedTask);
|
||||
|
||||
/**
|
||||
* @brief Helper function to initialize IOExpander
|
||||
*
|
||||
* @param expdr IOExpander instance to initialize
|
||||
*/
|
||||
void initIoExpander(MCP23017* expdr);
|
||||
|
||||
|
||||
#endif // __ACONNO_HELPERS_H__
|
||||
|
||||
|
||||
|
||||
+311
-52
@@ -10,102 +10,361 @@
|
||||
*/
|
||||
|
||||
#include "menuStates.h"
|
||||
#include "pictures.h"
|
||||
#include "aconnoHelpers.h"
|
||||
#include "GDEP015OC1.h"
|
||||
|
||||
extern TaskHandle_t welcomeTask;
|
||||
extern TaskHandle_t jumperTask;
|
||||
extern TaskHandle_t intro1Task;
|
||||
extern TaskHandle_t intro2Task;
|
||||
extern TaskHandle_t joystickTask;
|
||||
extern GDEP015OC1 epd;
|
||||
|
||||
State::~State()
|
||||
State::~State(){}
|
||||
|
||||
|
||||
State* UnimplementedState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("State destructor");
|
||||
return new Intro1State();
|
||||
}
|
||||
|
||||
void UnimplementedState::displayOnEpd()
|
||||
{
|
||||
epd.empty();
|
||||
epd.writeString("UNIMPLEMENTED", 60, 100, COLOR_BLACK);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
State* Intro1State::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
return new Intro2State();
|
||||
}
|
||||
|
||||
void Intro1State::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(intro1);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* WelcomeState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
State* Intro2State::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of WelcomeState");
|
||||
vTaskResume( welcomeTask );
|
||||
return new JumperState();
|
||||
return new Intro3State();
|
||||
}
|
||||
|
||||
State* JumperState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
void Intro2State::displayOnEpd()
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of JumperState");
|
||||
vTaskResume( jumperTask );
|
||||
return new JoystickState();
|
||||
}
|
||||
|
||||
State* JoystickState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of JoystickState");
|
||||
vTaskResume( joystickTask );
|
||||
return new SoundState();
|
||||
epd.drawImage(intro2);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* SoundState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
State* Intro3State::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of SoundState");
|
||||
return new RgbLedState();
|
||||
return new JoystickMenuState();
|
||||
}
|
||||
|
||||
void Intro3State::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(intro3);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* RgbLedState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
State* JoystickMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of RgbLedState");
|
||||
return new ServoState();
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new BleMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new SoundMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new JoystickMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
State* ServoState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
void JoystickMenuState::displayOnEpd()
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of ServoState");
|
||||
return new LdrState();
|
||||
epd.drawImage(joystick0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
State* LdrState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
|
||||
State* SoundMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of LdrState");
|
||||
return new PotentiometerState();
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new JoystickMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new RgbLedMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new SoundMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
State* PotentiometerState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
void SoundMenuState::displayOnEpd()
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of PotentiometerState");
|
||||
return new TempProbeState();
|
||||
epd.drawImage(sound0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
State* TempProbeState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
|
||||
State* RgbLedMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of TempProbeState");
|
||||
return new RelayState();
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new SoundMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new ServoMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new RgbLedMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
State* RelayState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
void RgbLedMenuState::displayOnEpd()
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of RelayState");
|
||||
return new LedState();
|
||||
epd.drawImage(rgb0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
State* LedState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
|
||||
State* ServoMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of LedState");
|
||||
return new InfraredState();
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new RgbLedMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new LdrMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new ServoMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
State* InfraredState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
void ServoMenuState::displayOnEpd()
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of InfraredState");
|
||||
return new GyroState();
|
||||
epd.drawImage(servo0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
State* GyroState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
|
||||
State* LdrMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of GyroState");
|
||||
return new BleState();
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new ServoMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new PotentiometerMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new LdrMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
State* BleState::buttonPressed(BTN_PRESSED btnPressed)
|
||||
void LdrMenuState::displayOnEpd()
|
||||
{
|
||||
NRF_LOG_INFO("virtual function buttonPressed of BleState");
|
||||
return new WelcomeState();
|
||||
epd.drawImage(ldr0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* PotentiometerMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new LdrMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new TempProbeMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new PotentiometerMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void PotentiometerMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(pot0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* TempProbeMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new PotentiometerMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new RelayMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new TempProbeMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void TempProbeMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(temp0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* RelayMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new TempProbeMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new LedMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new RelayMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void RelayMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(relay0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* LedMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new RelayMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new InfraredMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new LedMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void LedMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(led0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* InfraredMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new LedMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new GyroMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new InfraredMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void InfraredMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(ir0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* GyroMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new InfraredMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new BleMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new GyroMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void GyroMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(gyro0);
|
||||
epd.write();
|
||||
}
|
||||
|
||||
|
||||
State* BleMenuState::handleEvent(IOEXP_INT_SOURCE intSource)
|
||||
{
|
||||
switch (intSource)
|
||||
{
|
||||
case IOEXP_INT_SOURCE::JOY_UP:
|
||||
return new GyroMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_DOWN:
|
||||
return new JoystickMenuState();
|
||||
|
||||
case IOEXP_INT_SOURCE::JOY_CENTER:
|
||||
return new UnimplementedState();
|
||||
|
||||
default:
|
||||
return new BleMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
void BleMenuState::displayOnEpd()
|
||||
{
|
||||
epd.drawImage(BleBeacon);
|
||||
epd.write();
|
||||
}
|
||||
+96
-133
@@ -16,215 +16,178 @@
|
||||
#include "aconnoHelpers.h"
|
||||
#include "aconnoTasks.h"
|
||||
|
||||
/**
|
||||
* @brief Abstract state.
|
||||
*
|
||||
*/
|
||||
class State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
virtual State* buttonPressed(BTN_PRESSED btnPressed) = 0;
|
||||
|
||||
virtual ~State();
|
||||
};
|
||||
|
||||
class WelcomeState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
* @brief Function to handle an interrupt (a button press) in a context
|
||||
* of the current state
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @param intSource Id of the interrupt that occured,
|
||||
* see IOEXP_INT_SOURCE
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
virtual State* handleEvent(IOEXP_INT_SOURCE intSource) = 0;
|
||||
|
||||
/**
|
||||
* @brief Function to display the state on EPD.
|
||||
*/
|
||||
virtual void displayOnEpd() = 0;
|
||||
|
||||
};
|
||||
|
||||
class JumperState : public State
|
||||
class UnimplementedState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
};
|
||||
|
||||
class JoystickState : public State
|
||||
class Intro1State : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
};
|
||||
|
||||
class SoundState : public State
|
||||
class Intro2State : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
};
|
||||
|
||||
class RgbLedState : public State
|
||||
class Intro3State : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class ServoState : public State
|
||||
class JoystickMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class LdrState : public State
|
||||
class SoundMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class PotentiometerState : public State
|
||||
class RgbLedMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class TempProbeState : public State
|
||||
class ServoMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class RelayState : public State
|
||||
class LdrMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class LedState : public State
|
||||
class PotentiometerMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class InfraredState : public State
|
||||
class TempProbeMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class GyroState : public State
|
||||
class RelayMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class BleState : public State
|
||||
class LedMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Handler function when a button is pressed.
|
||||
*
|
||||
* @param btnPressed Id of the button that was pressed, see BTN_PRESSED
|
||||
* @return State* Returns the next state object (can be itself if the
|
||||
* state is not supposed to change)
|
||||
*/
|
||||
State* buttonPressed(BTN_PRESSED btnPressed);
|
||||
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class InfraredMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class GyroMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
class BleMenuState : public State
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
State* handleEvent(IOEXP_INT_SOURCE intSource);
|
||||
void displayOnEpd();
|
||||
|
||||
};
|
||||
|
||||
#endif //__MENU_STATES_H__
|
||||
File diff suppressed because it is too large
Load Diff
+28
-5
@@ -29,18 +29,41 @@ PROJ_SRC += \
|
||||
$(PROJ_DIR)/slots_and_params/arb_data.cpp \
|
||||
$(PROJ_DIR)/libs/aconnoGPIO/aconnoGPIO.cpp \
|
||||
$(PROJ_DIR)/libs/aconnoNordicPAL/aconnoNordicPAL.cpp \
|
||||
$(PROJ_DIR)/aconnoHelpers/menuStates.cpp
|
||||
|
||||
$(PROJ_DIR)/aconnoHelpers/menuStates.cpp \
|
||||
\
|
||||
$(PROJ_DIR)/libs/aconnoI2C/aconnoI2C.cpp \
|
||||
$(PROJ_DIR)/libs/aconnoSPI/aconnoSPI.cpp \
|
||||
$(PROJ_DIR)/libs/GDEP015OC1/GDEP015OC1.cpp \
|
||||
$(PROJ_DIR)/libs/MCP23017/MCP23017.cpp \
|
||||
\
|
||||
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_twi.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twi.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twim.c \
|
||||
\
|
||||
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_spi.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spi.c \
|
||||
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spim.c \
|
||||
|
||||
PROJ_INC += \
|
||||
$(PROJ_DIR)/libs/aconnoGPIO \
|
||||
$(PROJ_DIR)/libs/aconnoNordicPAL \
|
||||
$(PROJ_DIR)/config \
|
||||
$(PROJ_DIR)/config/ \
|
||||
$(PROJ_DIR)/aconnoHelpers/ \
|
||||
$(PROJ_DIR)/tasks/ \
|
||||
$(PROJ_DIR)/aconnoBLE/ \
|
||||
$(PROJ_DIR)/slots_and_params/ \
|
||||
\
|
||||
$(PROJ_DIR)/libs/aconnoI2C \
|
||||
$(PROJ_DIR)/libs/aconnoSPI \
|
||||
$(PROJ_DIR)/libs/GDEP015OC1 \
|
||||
$(PROJ_DIR)/libs/MCP23017 \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#$(PROJ_DIR)/BLE/nordicBLE/ \
|
||||
|
||||
|
||||
|
||||
# Source files common to all targets
|
||||
@@ -283,7 +306,7 @@ OPT = -O3 -g3
|
||||
# C flags common to all targets
|
||||
CFLAGS += $(OPT)
|
||||
CFLAGS += -DBOARD_PCA10040
|
||||
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
||||
#CFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
||||
CFLAGS += -DFLOAT_ABI_HARD
|
||||
CFLAGS += -DFREERTOS
|
||||
CFLAGS += -DNRF52
|
||||
@@ -312,7 +335,7 @@ ASMFLAGS += -mcpu=cortex-m4
|
||||
ASMFLAGS += -mthumb -mabi=aapcs
|
||||
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||
ASMFLAGS += -DBOARD_PCA10040
|
||||
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
||||
#ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
||||
ASMFLAGS += -DFLOAT_ABI_HARD
|
||||
ASMFLAGS += -DFREERTOS
|
||||
ASMFLAGS += -DNRF52
|
||||
|
||||
+9736
-4695
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file acn52832Bsp.h
|
||||
* @author Dominik Kotarski (d.kotarski@aconno.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2019-02-22
|
||||
*
|
||||
* @copyright Copyright (c) 2019
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* General IO pins
|
||||
*/
|
||||
#define PIN_BUTTON (25) //S1 gpio number (Active low)
|
||||
#define PIN_LED (26) //LD1 gpio number (Active low)
|
||||
#define PIN_IRLED (27) //LD4 gpio number (Active high)
|
||||
#define PIN_BUZZER (31) //LS1 gpio number (Active high)
|
||||
|
||||
#define PIN_LED_RED (22) //Module red LED
|
||||
#define PIN_LED_BLUE (23) //Module blue LED
|
||||
#define PIN_LED_GREEN (24) //Module green LED
|
||||
|
||||
/**
|
||||
* Alternate General IO pins
|
||||
* Connect:
|
||||
* (+, c, -) (Orange, Red, Brown)
|
||||
*/
|
||||
#define PIN_SERVO1 (25) //Servo1 gpio number
|
||||
#define PIN_SERVO2 (26) //Servo2 gpio number
|
||||
|
||||
/**
|
||||
* Analog to Digital Conversion (ADC) pins
|
||||
*/
|
||||
#define ADC_BAT (2) //Battery
|
||||
#define ADC_POT (28) //Potentiometer
|
||||
#define ADC_LIGHT (29) //Light Dependant Resistor
|
||||
#define ADC_TEMP (30) //Temperature Dependant Resistor
|
||||
|
||||
/**
|
||||
* Electronic Paper Display (EPD) pins
|
||||
*/
|
||||
#define PIN_EPD_CS (5) //EPD Chip select pin (Active low)
|
||||
#define PIN_EPD_DC (6) //EPD Data/Command pin (Data active high)
|
||||
#define PIN_EPD_RST (7) //EPD Reset pin (Active low)
|
||||
#define PIN_EPD_BUSY (8) //EPD Busy pin (Active low)
|
||||
#define PIN_EPD_SCK (4) //EPD SCK pin
|
||||
#define PIN_EPD_MOSI (3) //EPD MOSI pin
|
||||
#define PIN_EPD_MISO (0xFF) //EPD MISO pin not used
|
||||
|
||||
/**
|
||||
* IO Expander pins
|
||||
*/
|
||||
#define PIN_EXP_RST (19) //IO Expander reset pin
|
||||
#define EXPDR_A_INT (11) //IO Expander
|
||||
#define PIN_EXP_INT_A (11) //IO Expander interrupt for PORTA
|
||||
#define PIN_EXP_INT_B (12) //IO Expander interrupt for PORTB
|
||||
#define PIN_EXP_SDA (20) //TWI SCK pin
|
||||
#define PIN_EXP_SCL (21) //TWI SCL pin
|
||||
|
||||
/**
|
||||
* GPIO Pin configuration on IO Expander
|
||||
*/
|
||||
#define MCP23017_CENTER 7
|
||||
#define MCP23017_LEFT 5
|
||||
#define MCP23017_RIGHT 3
|
||||
#define MCP23017__UP 6
|
||||
#define MCP23017__DOWN 4
|
||||
#define MCP23017_SW2 8
|
||||
#define MCP23017_LED2 9
|
||||
#define MCP23017_REL1 11
|
||||
#define MCP23017_REL2 10
|
||||
|
||||
/**
|
||||
* Pins concerning TWI Addresses
|
||||
* Control bits are added by nrf_drv_twi
|
||||
*/
|
||||
#define TWI_EXPANDER_ADDR (0x40) //Port expander address
|
||||
#define TWI_AG_ADDR (0x6A << 1) //Accelerometer/Gyroscope address
|
||||
#define TWI_MAG_ADDR (0x1C << 1) //Magnetometer address
|
||||
|
||||
/**
|
||||
* Define structure used by bluetooth library
|
||||
* Define if BLE_LIB is defined as preprocessor symbol
|
||||
*/
|
||||
#ifdef BLE_LIB
|
||||
// Low frequency clock source to be used by the SoftDevice
|
||||
#define NRF_CLOCK_LFCLKSRC { \
|
||||
.source = NRF_CLOCK_LF_SRC_XTAL, \
|
||||
.rc_ctiv = 0, \
|
||||
.rc_temp_ctiv = 0, \
|
||||
.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef __ACN_BOARD_CONFIG_H__
|
||||
#define __ACN_BOARD_CONFIG_H__
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Submodule
+1
Submodule libs/GDEP015OC1 added at 22573c3230
@@ -0,0 +1,314 @@
|
||||
#include "MCP23017.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
|
||||
MCP23017::MCP23017(AconnoI2C &i2c, int i2cAddress) : _i2c(i2c)
|
||||
{
|
||||
MCP23017_i2cAddress = i2cAddress;
|
||||
reset(); // initialise chip to power-on condition
|
||||
}
|
||||
|
||||
MCP23017::MCP23017(AconnoI2C &i2c, int i2cAddress,
|
||||
int8_t pin,
|
||||
GPIO_DIR direction,
|
||||
GPIO_PULL pull,
|
||||
GPIO_EDGE edge,
|
||||
void (*pHandler)() ) : _i2c(i2c)
|
||||
{
|
||||
MCP23017_i2cAddress = i2cAddress;
|
||||
|
||||
GPIOPALintInit(pin,
|
||||
(uint8_t) direction,
|
||||
(uint8_t) pull,
|
||||
(uint8_t) edge,
|
||||
pHandler
|
||||
);
|
||||
|
||||
reset(); // initialise chip to power-on condition
|
||||
}
|
||||
|
||||
/*
|
||||
* reset
|
||||
* Set configuration (IOCON) and direction(IODIR) registers to initial state
|
||||
*/
|
||||
void MCP23017::reset()
|
||||
{
|
||||
//
|
||||
// First make sure that the device is in BANK=0 mode
|
||||
//
|
||||
writeRegister(0x05, (char)0x00);
|
||||
//
|
||||
// set direction registers to inputs
|
||||
//
|
||||
writeRegister(MCP23017_IODIR, (unsigned short)0xFFFF);
|
||||
//
|
||||
// set all other registers to zero (last of 10 registers is OLAT)
|
||||
//
|
||||
for (int reg_addr = 2 ; reg_addr <= MCP23017_OLAT ; reg_addr+=2)
|
||||
{
|
||||
writeRegister(reg_addr, (unsigned short)0x0000);
|
||||
}
|
||||
}
|
||||
|
||||
/* Config
|
||||
* set direction and pull-up registers
|
||||
*/
|
||||
void MCP23017::config(unsigned short dirConfig, unsigned short pullupConfig, unsigned short polarityConfig)
|
||||
{
|
||||
writeRegister(MCP23017_IODIR, dirConfig);
|
||||
|
||||
writeRegister(MCP23017_GPPU, pullupConfig);
|
||||
|
||||
writeRegister(MCP23017_IPOL, polarityConfig);
|
||||
}
|
||||
|
||||
/*
|
||||
* write_bit
|
||||
* Write a 1/0 to a single bit of the 16-bit port
|
||||
*/
|
||||
void MCP23017::writeBit( int value, int bitNumber, char regAddress)
|
||||
{
|
||||
unsigned short regData = readRegister(regAddress);
|
||||
|
||||
if (value == 0) {
|
||||
regData &= ~(1 << bitNumber);
|
||||
} else {
|
||||
regData |= 1 << bitNumber;
|
||||
}
|
||||
|
||||
writeRegister(regAddress, (unsigned short)regData);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a combination of bits to the 16-bit port
|
||||
*/
|
||||
void MCP23017::writeMask(unsigned short data, unsigned short mask)
|
||||
{
|
||||
unsigned short gpioData = readRegister(MCP23017_GPIO);
|
||||
gpioData = (gpioData & ~mask) | data;
|
||||
writeRegister(MCP23017_GPIO, (unsigned short)gpioData);
|
||||
}
|
||||
|
||||
/*
|
||||
* read_bit
|
||||
* Read a single bit from the 16-bit port
|
||||
*/
|
||||
int MCP23017::readBit(int bitNumber, char regAddress)
|
||||
{
|
||||
unsigned short regData = readRegister(regAddress);
|
||||
//NRF_LOG_INFO("Expdr -read bit %d", ((regData >> bitNumber) & 0x0001));
|
||||
return ((regData >> bitNumber) & 0x0001);
|
||||
}
|
||||
|
||||
/*
|
||||
* read_mask
|
||||
*/
|
||||
int MCP23017::readMask(unsigned short mask)
|
||||
{
|
||||
unsigned short gpioData = readRegister(MCP23017_GPIO);
|
||||
return (gpioData & mask);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* write_bit
|
||||
* Write a 1/0 to a single bit of the 16-bit GPIO port
|
||||
*/
|
||||
void MCP23017::writeGPIOBit( int value, int bitNumber)
|
||||
{
|
||||
unsigned short regData = readRegister(MCP23017_GPIO);
|
||||
|
||||
if (value == 0) {
|
||||
regData &= ~(1 << bitNumber);
|
||||
} else {
|
||||
regData |= 1 << bitNumber;
|
||||
}
|
||||
|
||||
//NRF_LOG_INFO("In write bit, I'll write %d on %hu", (unsigned short)regData, MCP23017_GPIO);
|
||||
writeRegister(MCP23017_GPIO, (unsigned short)regData);
|
||||
}
|
||||
|
||||
/*
|
||||
* read_bit
|
||||
* Read a single bit from the 16-bit port
|
||||
*/
|
||||
int MCP23017::readGPIOBit(int bitNumber)
|
||||
{
|
||||
unsigned short regData = readRegister(MCP23017_GPIO);
|
||||
//NRF_LOG_INFO("Expdr -read bit %d", ((regData >> bitNumber) & 0x0001));
|
||||
return ((regData >> bitNumber) & 0x0001);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* writeRegister
|
||||
* write a byte
|
||||
*/
|
||||
void MCP23017::writeRegister(char regAddress, char data)
|
||||
{
|
||||
_i2c.writeToReg(MCP23017_i2cAddress, regAddress, &data, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* write Register
|
||||
* write two bytes
|
||||
*/
|
||||
void MCP23017::writeRegister(char regAddress, unsigned short data)
|
||||
{
|
||||
char buffer[2];
|
||||
tmp_data.value16 = data;
|
||||
buffer[0] = tmp_data.value8[0];
|
||||
buffer[1] = tmp_data.value8[1];
|
||||
char *pbuffer = buffer;
|
||||
|
||||
_i2c.writeToReg(MCP23017_i2cAddress, regAddress, pbuffer, 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* readRegister
|
||||
*/
|
||||
int MCP23017::readRegister(char regAddress)
|
||||
{
|
||||
char buffer[2];
|
||||
char *pbuffer = buffer;
|
||||
_i2c.readFromReg(MCP23017_i2cAddress, regAddress, pbuffer, 2);
|
||||
|
||||
return ((int)(buffer[0] + (buffer[1]<<8)));
|
||||
}
|
||||
|
||||
/*
|
||||
* pinMode
|
||||
*/
|
||||
void MCP23017::pinMode(int pin, IODIR_MODE mode)
|
||||
{
|
||||
writeBit(pin, (mode==IODIR_MODE::INPUT), MCP23017_IODIR);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* digitalRead
|
||||
*/
|
||||
int MCP23017::digitalRead(int pin)
|
||||
{
|
||||
return (readRegister(MCP23017_GPIO) >> pin) & 0x1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* digitalWrite
|
||||
*/
|
||||
void MCP23017::digitalWrite(int pin, int val)
|
||||
{
|
||||
//If this pin is an INPUT pin, a write here will
|
||||
//enable the internal pullup
|
||||
//otherwise, it will set the OUTPUT voltage
|
||||
//as appropriate.
|
||||
bool isOutput = !(readRegister(MCP23017_IODIR) & 1<<pin);
|
||||
|
||||
if (isOutput) {
|
||||
//This is an output pin so just write the value
|
||||
writeBit(val, pin, MCP23017_GPIO);
|
||||
} else {
|
||||
//This is an input pin, so we need to enable the pullup
|
||||
writeBit(val, pin, MCP23017_GPPU);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* digitalWordRead
|
||||
*/
|
||||
unsigned short MCP23017::digitalWordRead()
|
||||
{
|
||||
return readRegister(MCP23017_GPIO);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* digitalWordWrite
|
||||
*/
|
||||
void MCP23017::digitalWordWrite(unsigned short word)
|
||||
{
|
||||
writeRegister(MCP23017_GPIO, word);
|
||||
}
|
||||
|
||||
/*
|
||||
* inputPolarityMask
|
||||
*/
|
||||
void MCP23017::inputPolarityMask(unsigned short mask)
|
||||
{
|
||||
writeRegister(MCP23017_IPOL, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* inputoutputMask
|
||||
*/
|
||||
void MCP23017::inputOutputMask(unsigned short mask)
|
||||
{
|
||||
writeRegister(MCP23017_IODIR, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* internalPullupMask
|
||||
*/
|
||||
void MCP23017::internalPullupMask(unsigned short mask)
|
||||
{
|
||||
writeRegister(MCP23017_GPPU, mask);
|
||||
}
|
||||
|
||||
void MCP23017::setuptInterrupts(uint8_t mirroring, uint8_t openDrain, uint8_t polarity)
|
||||
{
|
||||
//for port A
|
||||
writeBit(mirroring, 6, MCP23017_IOCON);
|
||||
writeBit(openDrain, 2, MCP23017_IOCON);
|
||||
writeBit(polarity, 1, MCP23017_IOCON);
|
||||
|
||||
//for port B
|
||||
writeBit(mirroring, 14, MCP23017_IOCON);
|
||||
writeBit(openDrain, 10, MCP23017_IOCON);
|
||||
writeBit(polarity, 9, MCP23017_IOCON);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* setInterruptPin
|
||||
*/
|
||||
void MCP23017::setupInterruptPin(uint8_t pin, INT_MODE mode)
|
||||
{
|
||||
// set the pin interrupt control (0 means change, 1 means compare against given value);
|
||||
// writeBit((mode!=INT_MODE::CHANGE), pin, MCP23017_INTCON);
|
||||
// if the mode is not CHANGE, we need to set up a default value, different value triggers interrupt
|
||||
|
||||
// In a RISING interrupt the default value is 0, interrupt is triggered when the pin goes to 1.
|
||||
// In a FALLING interrupt the default value is 1, interrupt is triggered when pin goes to 0.
|
||||
// writeBit((mode==INT_MODE::FALLING), pin, MCP23017_DEFVAL);
|
||||
|
||||
// enable the pin for interrupt
|
||||
writeBit((uint8_t)INT_MODE::HIGH, pin, MCP23017_GPINTEN);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* clearInterruptPin
|
||||
*/
|
||||
void MCP23017::clearInterruptPin(uint8_t pin)
|
||||
{
|
||||
// disable the pin for interrupt
|
||||
writeBit( (uint8_t)INT_MODE::LOW, pin, MCP23017_GPINTEN);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* getLastInterruptPin
|
||||
*/
|
||||
uint8_t MCP23017::getLastInterruptPin()
|
||||
{
|
||||
uint8_t intf=readRegister(MCP23017_INTF);
|
||||
|
||||
for(int i=0;i<16;i++)
|
||||
if ( intf & (1 << i) )
|
||||
return i;
|
||||
|
||||
return MCP23017_INT_ERR;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
#ifndef MCP23017_H
|
||||
#define MCP23017_H
|
||||
|
||||
#include "aconnoI2C.h"
|
||||
#include "aconnoGPIO.h"
|
||||
#include <stdint.h>
|
||||
#include "aconno_bsp.h"
|
||||
|
||||
//
|
||||
// Register defines from data sheet - we set IOCON.BANK to 0
|
||||
// as it is easier to manage the registers sequentially.
|
||||
//
|
||||
|
||||
#define MCP23017_IODIR 0x00
|
||||
#define MCP23017_IPOL 0x02
|
||||
#define MCP23017_GPINTEN 0x04
|
||||
#define MCP23017_DEFVAL 0x06
|
||||
#define MCP23017_INTCON 0x08
|
||||
#define MCP23017_IOCON 0x0A
|
||||
#define MCP23017_GPPU 0x0C
|
||||
#define MCP23017_INTF 0x0E
|
||||
#define MCP23017_INTCAP 0x10
|
||||
#define MCP23017_GPIO 0x12
|
||||
#define MCP23017_OLAT 0x14
|
||||
|
||||
#define MCP23017_I2C_BASE_ADDRESS 0x40
|
||||
#define MCP23017_INT_ERR 255
|
||||
|
||||
#define MCP23017_DIR_OUTPUT 0
|
||||
#define MCP23017_DIR_INPUT 1
|
||||
|
||||
union {
|
||||
uint8_t value8[2];
|
||||
uint16_t value16;
|
||||
} tmp_data;
|
||||
|
||||
enum class INT_MODE : uint8_t
|
||||
{
|
||||
LOW = 0, //!< 0
|
||||
HIGH = 1, //!< 1
|
||||
CHANGE = 2, //!< 2
|
||||
RISING = 3, //!< 3
|
||||
FALLING = 4 //!< 4
|
||||
};
|
||||
|
||||
enum class IODIR_MODE : uint8_t
|
||||
{
|
||||
OUTPUT = 0, //!< 0
|
||||
INPUT = 1, //!< 1
|
||||
};
|
||||
|
||||
class MCP23017 {
|
||||
|
||||
public:
|
||||
/** Constructor for the MCP23017 connected to specified I2C pins at a specific address
|
||||
*
|
||||
* 16-bit I/O expander with I2C interface
|
||||
*
|
||||
* @param i2cAddress I2C address
|
||||
*/
|
||||
MCP23017(AconnoI2C &i2c, int i2cAddress);
|
||||
|
||||
MCP23017(AconnoI2C &i2c, int i2cAddress,
|
||||
int8_t pin,
|
||||
GPIO_DIR direction,
|
||||
GPIO_PULL pull,
|
||||
GPIO_EDGE edge,
|
||||
void (*pHandler)() );
|
||||
|
||||
/** Reset MCP23017 device to its power-on state
|
||||
*/
|
||||
void reset(void);
|
||||
|
||||
/** Configure an MCP23017 device
|
||||
*
|
||||
* @param dir_config data direction value (1 = input, 0 = output)
|
||||
* @param pullup_config 100k pullup value (1 = enabled, 0 = disabled)
|
||||
* @param polarity_config polarity value (1 = flip, 0 = normal)
|
||||
*/
|
||||
void config(unsigned short dirConfig, unsigned short pullupConfig, unsigned short polarityConfig);
|
||||
|
||||
void writeRegister(char regAddress, char data);
|
||||
void writeRegister(char regAddress, unsigned short data);
|
||||
int readRegister(char regAddress);
|
||||
|
||||
/** Write a 0/1 value to an output bit
|
||||
*
|
||||
* @param value 0 or 1
|
||||
* @param bit_number bit number range 0 --> 15
|
||||
* @param regAddress address of register (char)
|
||||
*/
|
||||
void writeBit(int value, int bitNumber, char regAddress);
|
||||
|
||||
/** Write a masked 16-bit value to the device
|
||||
*
|
||||
* @param data 16-bit data value
|
||||
* @param mask 16-bit mask value
|
||||
*/
|
||||
void writeMask(unsigned short data, unsigned short mask);
|
||||
|
||||
/** Read a 0/1 value from an input bit
|
||||
*
|
||||
* @param bit_number bit number range 0 --> 15
|
||||
* @return 0/1 value read
|
||||
*/
|
||||
int readBit(int bitNumber, char regAddress);
|
||||
|
||||
/** Read a 16-bit value from the device and apply mask
|
||||
*
|
||||
* @param mask 16-bit mask value
|
||||
* @return 16-bit data with mask applied
|
||||
*/
|
||||
int readMask(unsigned short mask);
|
||||
|
||||
void writeGPIOBit( int value, int bitNumber);
|
||||
int readGPIOBit(int bitNumber);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* pinmode
|
||||
* Set units to sequential, bank0 mode
|
||||
*/
|
||||
void pinMode(int pin, IODIR_MODE mode);
|
||||
void digitalWrite(int pin, int val);
|
||||
int digitalRead(int pin);
|
||||
|
||||
// These provide a more advanced mapping of the chip functionality
|
||||
// See the data sheet for more information on what they do
|
||||
|
||||
//Returns a word with the current pin states (ie contents of the GPIO register)
|
||||
unsigned short digitalWordRead();
|
||||
// Allows you to write a word to the GPIO register
|
||||
void digitalWordWrite(unsigned short w);
|
||||
// Sets up the polarity mask that the MCP23017 supports
|
||||
// if set to 1, it will flip the actual pin value.
|
||||
void inputPolarityMask(unsigned short mask);
|
||||
//Sets which pins are inputs or outputs (1 = input, 0 = output) NB Opposite to arduino's
|
||||
//definition for these
|
||||
void inputOutputMask(unsigned short mask);
|
||||
// Allows enabling of the internal 100k pullup resisters (1 = enabled, 0 = disabled)
|
||||
void internalPullupMask(unsigned short mask);
|
||||
|
||||
void setuptInterrupts(uint8_t mirroring, uint8_t openDrain, uint8_t polarity);
|
||||
|
||||
void setupInterruptPin(uint8_t pin, INT_MODE mode);
|
||||
|
||||
void clearInterruptPin(uint8_t pin);
|
||||
|
||||
uint8_t getLastInterruptPin();
|
||||
|
||||
protected:
|
||||
AconnoI2C _i2c;
|
||||
int MCP23017_i2cAddress; // physical I2C address
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Submodule
+1
Submodule libs/aconnoI2C added at 0149a86a3b
+1
-1
Submodule libs/aconnoNordicPAL updated: afdcede4cf...906a778f1c
Submodule
+1
Submodule libs/aconnoSPI added at 6fc044a29d
+1
-4
@@ -43,7 +43,7 @@ extern TaskHandle_t m_logger_thread;
|
||||
|
||||
|
||||
|
||||
/**@brief Function for application main entry.
|
||||
/** @brief Function for application main entry.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
@@ -58,12 +58,9 @@ int main(void)
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
}
|
||||
|
||||
//xTaskCreate(blinkyFunction, "BLINKY", 256, NULL, 1, &blinkyTask);
|
||||
//xTaskCreate(blinkyFunction2, "BLINKY2", 256, NULL, 1, &blinkyTask2);
|
||||
xTaskCreate(menuStateMachineTaskFunction, "MenuStateMachine", 256, NULL, 1,
|
||||
&menuStateMachineTask);
|
||||
|
||||
|
||||
// Activate deep sleep mode.
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
|
||||
+90
-87
@@ -17,41 +17,52 @@
|
||||
#include "semphr.h"
|
||||
#include "aconnoHelpers.h"
|
||||
#include "menuStates.h"
|
||||
#include "acn52832Bsp.h"
|
||||
|
||||
/*epd*/
|
||||
#include "aconnoSPI.h"
|
||||
#include "GDEP015OC1.h"
|
||||
#include "pictures.h"
|
||||
|
||||
/*ioexp*/
|
||||
#include "aconnoI2C.h"
|
||||
#include "MCP23017.h"
|
||||
|
||||
TaskHandle_t initTask;
|
||||
TaskHandle_t blinkyTask;
|
||||
TaskHandle_t blinkyTask2;
|
||||
TaskHandle_t batteryServiceTaskMy;
|
||||
TaskHandle_t menuStateMachineTask;
|
||||
TaskHandle_t getInterruptSourceTask;
|
||||
|
||||
TaskHandle_t welcomeTask;
|
||||
TaskHandle_t jumperTask;
|
||||
TaskHandle_t joystickTask;
|
||||
|
||||
BTN_PRESSED btnPressed = BTN_PRESSED::NOTHING;
|
||||
IOEXP_INT_SOURCE intSource = IOEXP_INT_SOURCE::NOTHING;
|
||||
State* pMenuState;
|
||||
|
||||
|
||||
SemaphoreHandle_t stateMachineSemaphore;
|
||||
SemaphoreHandle_t getInterruptSourceSemaphore;
|
||||
|
||||
AconnoGPIO led1(LED1_PIN,GPIO_DIR::GPIO_OUTPUT);
|
||||
AconnoGPIO led2(LED2_PIN,GPIO_DIR::GPIO_OUTPUT);
|
||||
AconnoGPIO led3(LED3_PIN,GPIO_DIR::GPIO_OUTPUT);
|
||||
|
||||
AconnoGPIO btn1(BTN_1_PIN,
|
||||
AconnoGPIO ledRed(LED1_PIN,GPIO_DIR::GPIO_OUTPUT);
|
||||
AconnoGPIO ledBlue(LED2_PIN,GPIO_DIR::GPIO_OUTPUT);
|
||||
AconnoGPIO ledGreen(LED3_PIN,GPIO_DIR::GPIO_OUTPUT);
|
||||
|
||||
/* AconnoGPIO btn1(BTN_1_PIN,
|
||||
GPIO_DIR::GPIO_INTERRUPT,
|
||||
GPIO_PULL::OFF,
|
||||
GPIO_EDGE::FALLING,
|
||||
mainMenuInterruptCallback);
|
||||
testCallback); */
|
||||
|
||||
AconnoSPI spi(PIN_EPD_MISO, PIN_EPD_MOSI, PIN_EPD_SCK);
|
||||
GDEP015OC1 epd(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY);
|
||||
|
||||
AconnoI2C i2c (PIN_EXP_SDA, PIN_EXP_SCL);
|
||||
|
||||
MCP23017 expdr (i2c, TWI_EXPANDER_ADDR, EXPDR_A_INT,
|
||||
GPIO_DIR::GPIO_INTERRUPT,
|
||||
GPIO_PULL::OFF,
|
||||
GPIO_EDGE::FALLING,
|
||||
mainMenuInterruptCallback);
|
||||
|
||||
void mainMenuInterruptCallback()
|
||||
{
|
||||
/* todo: possibly no debounce */
|
||||
NRF_LOG_DEBUG("button pressed");
|
||||
/* todo: get real button pressed when the joystick is ported */
|
||||
btnPressed = BTN_PRESSED::DOWN ;
|
||||
xSemaphoreGive( stateMachineSemaphore );
|
||||
}
|
||||
|
||||
/**< Definition of Logger thread. */
|
||||
#if NRF_LOG_ENABLED
|
||||
@@ -75,87 +86,92 @@ void logTaskFunction(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void blinkyFunction(void *arg)
|
||||
void testCallback()
|
||||
{
|
||||
nrf_gpio_cfg_output(LED1_PIN);
|
||||
while(1)
|
||||
{
|
||||
nrf_gpio_pin_toggle(LED1_PIN);
|
||||
vTaskDelay(BLINKY_1_DELAY_MS);
|
||||
NRF_LOG_INFO("Blinky 1 =) ");
|
||||
}
|
||||
ledRed.toggle();
|
||||
ledBlue.toggle();
|
||||
ledGreen.toggle();
|
||||
}
|
||||
|
||||
void blinkyFunction2(void *arg)
|
||||
void mainMenuInterruptCallback()
|
||||
{
|
||||
nrf_gpio_cfg_output(LED1_PIN);
|
||||
while(1)
|
||||
{
|
||||
nrf_gpio_pin_toggle(LED1_PIN);
|
||||
vTaskDelay(BLINKY_2_DELAY_MS);
|
||||
NRF_LOG_INFO("Blinky 2 =) ");
|
||||
}
|
||||
|
||||
// resume task to get button
|
||||
xSemaphoreGive( getInterruptSourceSemaphore );
|
||||
}
|
||||
|
||||
void welcomeTaskFunction(void *arg)
|
||||
void getInterruptSourceFunction(void *arg)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
vTaskSuspend(NULL);
|
||||
led1.toggle();
|
||||
}
|
||||
}
|
||||
if( xSemaphoreTake( getInterruptSourceSemaphore, portMAX_DELAY ) == pdTRUE )
|
||||
{
|
||||
waitMs(50);
|
||||
/* todo: actually return real interrupt source */
|
||||
uint8_t intSrcPin = expdr.getLastInterruptPin();
|
||||
if (expdr.readGPIOBit(intSrcPin))
|
||||
{
|
||||
//ignore rising edge
|
||||
intSource = IOEXP_INT_SOURCE::NOTHING;
|
||||
}
|
||||
else
|
||||
{
|
||||
intSource = (IOEXP_INT_SOURCE)intSrcPin;
|
||||
/* let mainMenu stateMachine task handle the button pressed*/
|
||||
vTaskResume(menuStateMachineTask);
|
||||
}
|
||||
|
||||
void jumperTaskFunction(void *arg)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
vTaskSuspend(NULL);
|
||||
led2.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
void joystickTaskFunction(void *arg)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
vTaskSuspend(NULL);
|
||||
led3.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void menuStateMachineTaskFunction(void *arg)
|
||||
{
|
||||
NRF_LOG_INFO("StateMachineTaskStart");
|
||||
pMenuState = new WelcomeState();
|
||||
|
||||
/* init i2c */
|
||||
i2c.init();
|
||||
|
||||
/* init ioexpander */
|
||||
initIoExpander(&expdr);
|
||||
expdr.setupInterruptPin(MCP23017_CENTER, INT_MODE::FALLING);
|
||||
expdr.setupInterruptPin(MCP23017__UP, INT_MODE::FALLING);
|
||||
expdr.setupInterruptPin(MCP23017__DOWN, INT_MODE::FALLING);
|
||||
expdr.setupInterruptPin(MCP23017_RIGHT, INT_MODE::FALLING);
|
||||
expdr.setupInterruptPin(MCP23017_LEFT, INT_MODE::FALLING);
|
||||
/* end ioexpander init */
|
||||
|
||||
/* Turn off leds */
|
||||
ledRed.set();
|
||||
ledBlue.set();
|
||||
ledGreen.set();
|
||||
|
||||
/* Initialize state machine*/
|
||||
pMenuState = new Intro1State();
|
||||
pMenuState->displayOnEpd();
|
||||
|
||||
/* Create all tasks that will be used */
|
||||
xTaskCreate(welcomeTaskFunction, "WelcomeTask", 256, NULL, 1, &welcomeTask);
|
||||
xTaskCreate(jumperTaskFunction, "WelcomeTask", 256, NULL, 1, &jumperTask);
|
||||
xTaskCreate(joystickTaskFunction, "WelcomeTask", 256, NULL, 1, &joystickTask);
|
||||
xTaskCreate(getInterruptSourceFunction, "GetInterruptSourceTask", 256, NULL,
|
||||
1, &getInterruptSourceTask);
|
||||
|
||||
/* Attempt to create a semaphore. */
|
||||
stateMachineSemaphore = xSemaphoreCreateBinary();
|
||||
if( stateMachineSemaphore == NULL )
|
||||
/* Create all semaphores that will be used */
|
||||
getInterruptSourceSemaphore= xSemaphoreCreateBinary();
|
||||
if( getInterruptSourceSemaphore == NULL )
|
||||
{
|
||||
NRF_LOG_ERROR("ERROR, not enough space available to create semaphore!");
|
||||
}
|
||||
/* End semaphore creation */
|
||||
|
||||
|
||||
/* Main loop*/
|
||||
while(1)
|
||||
{
|
||||
if( xSemaphoreTake( stateMachineSemaphore, portMAX_DELAY ) == pdTRUE )
|
||||
{
|
||||
|
||||
/* todo: delete could make problems if the same state is returned
|
||||
*/
|
||||
vTaskSuspend(NULL);
|
||||
|
||||
State* newMenuState = pMenuState->buttonPressed(btnPressed);
|
||||
/* todo: delete could make problems if the same state is returned */
|
||||
|
||||
State* newMenuState = pMenuState->handleEvent(intSource);
|
||||
delete pMenuState;
|
||||
pMenuState = newMenuState;
|
||||
NRF_LOG_INFO("StateMachineLoopEnd\n");
|
||||
|
||||
}
|
||||
pMenuState->displayOnEpd();
|
||||
|
||||
/* todo: consider pre-creating all state objects instead of
|
||||
dinamically creating and destroying objects */
|
||||
@@ -165,19 +181,6 @@ void menuStateMachineTaskFunction(void *arg)
|
||||
|
||||
/* todo: consider dynamically deleting tasks after a certain treshold
|
||||
in case memory becomes a problem */
|
||||
|
||||
/* todo: main menu task waits at semaphore until a button is pressed,
|
||||
then go into a switch case that will decide which state is next from
|
||||
the button last pressed and the current state, alternatively,
|
||||
instead of switching states it can do nothing (in case of a button
|
||||
pressed that does nothing), or remain in
|
||||
the same menu state to start the example task and remain blocked at the
|
||||
semaphore until the task is finished (that task will redefine
|
||||
the button callback vector to tailor the joystick inputs
|
||||
towards its example, defining one button as an exit point that
|
||||
will renew the original menu callback vector and return the user
|
||||
to the menu) */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,5 +81,7 @@ void joystickTaskFunction(void *arg);
|
||||
*
|
||||
*/
|
||||
void mainMenuInterruptCallback();
|
||||
void testCallback();
|
||||
|
||||
|
||||
#endif // __ACONNO_TASKS_H__
|
||||
Reference in New Issue
Block a user