Browse Source

Added support for Mechanical Buttons Extension

v0.9.4
Guy Turcotte 2 years ago
parent
commit
c3c663ce63
  1. 4
      CHANGES.md
  2. 5
      include/drivers/backlight.hpp
  3. 5
      include/drivers/battery.hpp
  4. 4
      include/drivers/eink.hpp
  5. 4
      include/drivers/eink_10.hpp
  6. 4
      include/drivers/eink_6.hpp
  7. 5
      include/drivers/frame_buffer.hpp
  8. 24
      include/drivers/inkplate_platform.hpp
  9. 5
      include/drivers/mcp23017.hpp
  10. 42
      include/drivers/press_keys.hpp
  11. 5
      include/drivers/touch_keys.hpp
  12. 10
      include/graphical/inkplate.hpp
  13. 5
      include/services/esp.hpp
  14. 5
      include/services/network_client.hpp
  15. 5
      include/services/sd_card.hpp
  16. 5
      include/services/wire.hpp
  17. 5
      include/tools/non_copyable.hpp
  18. 16
      src/drivers/inkplate_platform.cpp
  19. 52
      src/drivers/press_keys.cpp

4
CHANGES.md

@ -86,3 +86,7 @@ This name reflect more what it is. This class will is currently under eavy chang
## FrameBuffer classes
A hierarchy of frame buffer classes has been added. These allow for flexible adaptation to the different geometry of devices and pixel sizes.
## press_keys (.hpp, .cpp)
This class implements the Buttons Extension: 6 mechanical press buttons that replace the touch keys. To be used, at compile time, BUTTONS_EXTENSION must be #defined. The touch_keys class will then not be included.

5
include/drivers/backlight.hpp

@ -1,5 +1,4 @@
#ifndef __BACKLIGHT_H__
#define __BACKLIGHT_H__
#pragma once
#if defined(INKPLATE_6PLUS)
@ -20,5 +19,3 @@ class Backlight
};
#endif
#endif

5
include/drivers/battery.hpp

@ -1,5 +1,4 @@
#ifndef __BATTERY_HPP__
#define __BATTERY_HPP__
#pragma once
#include "non_copyable.hpp"
#include "mcp23017.hpp"
@ -18,5 +17,3 @@ class Battery : NonCopyable
const MCP23017::Pin BATTERY_SWITCH = MCP23017::Pin::IOPIN_9;
};
#endif

4
include/drivers/eink.hpp

@ -1,5 +1,4 @@
#ifndef __EINK_HPP__
#define __EINK_HPP__
#pragma once
#include "logging.hpp"
#include "frame_buffer.hpp"
@ -129,4 +128,3 @@ class EInk
inline void vcom_clear() { mcp_int.digital_write(VCOM, MCP23017::SignalLevel::LOW ); }
};
#endif

4
include/drivers/eink_10.hpp

@ -21,8 +21,7 @@ Distributed as-is; no warranty is given.
*/
#ifdef INKPLATE_10
#ifndef __EINK10_HPP__
#define __EINK10_HPP__
#pragma once
#include <cinttypes>
#include <cstring>
@ -112,4 +111,3 @@ class EInk10 : public EInk, NonCopyable
};
#endif
#endif

4
include/drivers/eink_6.hpp

@ -21,8 +21,7 @@ Distributed as-is; no warranty is given.
*/
#ifdef INKPLATE_6
#ifndef __EINK6_HPP__
#define __EINK6_HPP__
#pragma once
#include <cinttypes>
#include <cstring>
@ -111,4 +110,3 @@ class EInk6 : public EInk, NonCopyable
};
#endif
#endif

5
include/drivers/frame_buffer.hpp

@ -1,5 +1,4 @@
#ifndef __FRAME_BUFFER_HPP__
#define __FRAME_BUFFER_HPP__
#pragma once
#include "logging.hpp"
@ -43,5 +42,3 @@ class FrameBuffer3Bit : public FrameBuffer
public:
FrameBuffer3Bit(int16_t w, int16_t h, int32_t s) : FrameBuffer(w, h, s, (uint8_t) 0x77) {}
};
#endif

24
include/drivers/inkplate_platform.hpp

@ -15,8 +15,7 @@ If you have any questions about licensing, please contact techsupport@e-radionic
Distributed as-is; no warranty is given.
*/
#ifndef __INKPLATE_PLATFORM_HPP__
#define __INKPLATE_PLATFORM_HPP__
#pragma once
#include <cstdint>
@ -24,15 +23,24 @@ Distributed as-is; no warranty is given.
#include "mcp23017.hpp"
#include "battery.hpp"
#include "touch_keys.hpp"
#include "eink.hpp"
#include "eink_6.hpp"
#include "eink_10.hpp"
#if defined(BUTTONS_EXTENSION)
#include "press_keys.hpp"
#else
#include "touch_keys.hpp"
#endif
#if __INKPLATE_PLATFORM__
MCP23017 mcp_int(0x20);
Battery battery(mcp_int);
TouchKeys touch_keys(mcp_int);
#if defined(BUTTONS_EXTENSION)
PressKeys press_keys(mcp_int);
#else
TouchKeys touch_keys(mcp_int);
#endif
#if defined(INKPLATE_6)
EInk6 e_ink(mcp_int);
@ -45,7 +53,11 @@ Distributed as-is; no warranty is given.
#else
extern MCP23017 mcp_int;
extern Battery battery;
extern TouchKeys touch_keys;
#if defined(BUTTONS_EXTENSION)
extern PressKeys press_keys;
#else
extern TouchKeys touch_keys;
#endif
#if defined(INKPLATE_6)
extern EInk6 e_ink;
@ -88,5 +100,3 @@ class InkPlatePlatform : NonCopyable
#else
extern InkPlatePlatform & inkplate_platform;
#endif
#endif

5
include/drivers/mcp23017.hpp

@ -20,8 +20,7 @@ If you have any questions about licensing, please contact techsupport@e-radionic
Distributed as-is; no warranty is given.
*/
#ifndef __MCP_HPP__
#define __MCP_HPP__
#pragma once
#include <cinttypes>
#include <cstring>
@ -138,5 +137,3 @@ class MCP23017 : NonCopyable
void set_ports(uint16_t values);
uint16_t get_ports();
};
#endif

42
include/drivers/press_keys.hpp

@ -0,0 +1,42 @@
#pragma once
#include "non_copyable.hpp"
#include "mcp23017.hpp"
class PressKeys : NonCopyable
{
public:
enum class Key : uint8_t { KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5 };
PressKeys(MCP23017 & _mcp) : mcp(_mcp) {}
bool setup();
/**
* @brief Read a specific presskey
*
* Read one of the six presskeys.
*
* @param key presskey (KEY_0, KEY_1, or KEY_2)
* @return uint8_t 1 if pressed, 0 if not
*/
uint8_t read_key(Key key);
/**
* @brief Read all keys
*
* @return uint8_t keys bitmap (bit = 1 if pressed) keys 0..5 are mapped to bits 0 to 5.
*/
uint8_t read_all_keys();
private:
static constexpr char const * TAG = "PressKeys";
MCP23017 & mcp;
const MCP23017::Pin PRESS_0 = MCP23017::Pin::IOPIN_10;
const MCP23017::Pin PRESS_1 = MCP23017::Pin::IOPIN_11;
const MCP23017::Pin PRESS_2 = MCP23017::Pin::IOPIN_12;
const MCP23017::Pin PRESS_3 = MCP23017::Pin::IOPIN_13;
const MCP23017::Pin PRESS_4 = MCP23017::Pin::IOPIN_14;
const MCP23017::Pin PRESS_5 = MCP23017::Pin::IOPIN_15;
};

5
include/drivers/touch_keys.hpp

@ -1,5 +1,4 @@
#ifndef __TOUCH_KEYS_HPP__
#define __TOUCH_KEYS_HPP__
#pragma once
#include "non_copyable.hpp"
#include "mcp23017.hpp"
@ -38,5 +37,3 @@ class TouchKeys : NonCopyable
const MCP23017::Pin TOUCH_2 = MCP23017::Pin::IOPIN_12;
};
#endif

10
include/graphical/inkplate.hpp

@ -14,8 +14,7 @@ If you have any questions about licensing, please contact techsupport@e-radionic
Distributed as-is; no warranty is given.
*/
#ifndef __INKPLATE_H__
#define __INKPLATE_H__
#pragma once
#include "defines.hpp"
@ -41,7 +40,11 @@ class Inkplate : public Graphics
int8_t readTemperature() { return e_ink.read_temperature(); }
uint8_t readTouchpad(int c) { return touch_keys.read_key((TouchKeys::Key) c); }
#if defined(BUTTONS_EXTENSION)
uint8_t readPresskey(int c) { return press_keys.read_key((PressKeys::Key) c); }
#else
uint8_t readTouchpad(int c) { return touch_keys.read_key((TouchKeys::Key) c); }
#endif
inline void disconnect() { network_client.disconnect(); }
inline bool isConnected() { return network_client.isConnected(); }
@ -53,4 +56,3 @@ class Inkplate : public Graphics
bool sdCardInit() { return true; }
};
#endif

5
include/services/esp.hpp

@ -2,8 +2,7 @@
//
// MIT License. Look at file licenses.txt for details.
#ifndef __ESP_HPP__
#define __ESP_HPP__
#pragma once
#include <cinttypes>
@ -78,5 +77,3 @@ class ESP
ESP_LOGD(TAG, "+----------------------+");
}
};
#endif

5
include/services/network_client.hpp

@ -15,8 +15,7 @@ If you have any questions about licensing, please contact techsupport@e-radionic
Distributed as-is; no warranty is given.
*/
#ifndef __NETWORKCLIENT_H__
#define __NETWORKCLIENT_H__
#pragma once
#include <cstdint>
@ -41,5 +40,3 @@ class NetworkClient
#else
extern NetworkClient network_client;
#endif
#endif

5
include/services/sd_card.hpp

@ -1,5 +1,4 @@
#ifndef __SD_CARD_HPP__
#define __SD_CARD_HPP__
#pragma once
class SDCard
{
@ -18,5 +17,3 @@ class SDCard
private:
static constexpr char const * TAG = "SDCard";
};
#endif

5
include/services/wire.hpp

@ -2,8 +2,7 @@
//
// MIT License. Look at file licenses.txt for details.
#ifndef __WIRE_HPP__
#define __WIRE_HPP__
#pragma once
#include <cinttypes>
@ -54,5 +53,3 @@ class Wire : NonCopyable
#else
extern Wire & wire;
#endif
#endif

5
include/tools/non_copyable.hpp

@ -2,8 +2,7 @@
//
// MIT License. Look at file licenses.txt for details.
#ifndef __NON_COPYABLE_HPP__
#define __NON_COPYABLE_HPP__
#pragma once
/**
* @brief Make children classes impossible to be copied.
@ -23,5 +22,3 @@ class NonCopyable
constexpr NonCopyable() = default;
~NonCopyable() = default;
};
#endif

16
src/drivers/inkplate_platform.cpp

@ -8,10 +8,15 @@
#include "esp.hpp"
#include "eink.hpp"
#include "eink_6.hpp"
#include "touch_keys.hpp"
#include "battery.hpp"
#include "sd_card.hpp"
#if defined(BUTTONS_EXTENSION)
#include "press_keys.hpp"
#else
#include "touch_keys.hpp"
#endif
#include "esp_sleep.h"
InkPlatePlatform InkPlatePlatform::singleton;
@ -27,8 +32,13 @@ InkPlatePlatform::setup()
// Battery
if (!battery.setup()) return false;
// Setup Touch keys
if (!touch_keys.setup()) return false;
#if defined(BUTTONS_EXTENSION)
// Setup Press keys
if (!press_keys.setup()) return false;
#else
// Setup Touch keys
if (!touch_keys.setup()) return false;
#endif
// Mount and check the SD Card
if (!SDCard::setup()) return false;

52
src/drivers/press_keys.cpp

@ -0,0 +1,52 @@
#define __PRESS_KEYS__ 1
#include "press_keys.hpp"
#include "wire.hpp"
bool
PressKeys::setup()
{
Wire::enter();
mcp.set_direction(PRESS_0, MCP23017::PinMode::INPUT_PULLUP);
mcp.set_direction(PRESS_1, MCP23017::PinMode::INPUT_PULLUP);
mcp.set_direction(PRESS_2, MCP23017::PinMode::INPUT_PULLUP);
mcp.set_direction(PRESS_3, MCP23017::PinMode::INPUT_PULLUP);
mcp.set_direction(PRESS_4, MCP23017::PinMode::INPUT_PULLUP);
mcp.set_direction(PRESS_5, MCP23017::PinMode::INPUT_PULLUP);
// Prepare the MCP device to allow for interrupts
// coming from any of the presskeys. Interrupts will be raised
// for any change of state of the 6 presskeys. The GPIO_NUM_34
// must be programmed as per the ESP-IDF documentation to get
// some interrupts.
mcp.set_int_pin(PRESS_0, MCP23017::IntMode::FALLING);
mcp.set_int_pin(PRESS_1, MCP23017::IntMode::FALLING);
mcp.set_int_pin(PRESS_2, MCP23017::IntMode::FALLING);
mcp.set_int_pin(PRESS_3, MCP23017::IntMode::FALLING);
mcp.set_int_pin(PRESS_4, MCP23017::IntMode::FALLING);
mcp.set_int_pin(PRESS_5, MCP23017::IntMode::FALLING);
mcp.set_int_output(MCP23017::IntPort::INTPORTB, false, false, MCP23017::SignalLevel::HIGH);
Wire::leave();
return true;
}
uint8_t
PressKeys::read_all_keys()
{
Wire::enter();
uint16_t value = mcp.get_ports();
Wire::leave();
return ((value >> 10) & 0x3F) ^ 0x3F;
}
uint8_t
PressKeys::read_key(Key key)
{
Wire::enter();
MCP23017::SignalLevel value = mcp.digital_read((MCP23017::Pin)(((uint8_t)key) + 10)); // Not clean
Wire::leave();
return value == MCP23017::SignalLevel::HIGH ? 0 : 1;
}
Loading…
Cancel
Save