
#include "RBPXPLRTERM_base.h"
#include "RBPXPLRTERM_config.h"
#include "loopScanner.h"
#include "textBuffer.h"
#include "timeouts.h"

#ifndef _keyboard_h
#define _keyboard_h


#define FUNC_A 129
#define FUNC_B 130
#define FUNC_C 131
#define FUNC_D 132

#define KBD_UP     141
#define KBD_RIGHT  142
#define KBD_DOWN   143
#define KBD_LEFT   144

#ifdef KBD_RBPXPLR

/*
 * this exposes the definitions for the standard keyboard interface provided by the RBPXPLR with its 4 non-multiplexed buttons
 */

#define KBD_NUMKEYS 4

#define KBD_RELEASEOFFSET KBD_NUMKEYS

#define BUTTON_UP_PIN     10
#define BUTTON_RIGHT_PIN  11
#define BUTTON_DOWN_PIN   14
#define BUTTON_LEFT_PIN   15
//
#define BUTTON_INIT_MODE  INPUT_PULLDOWN
//
#define KBD_BUTTON_UP     0
#define KBD_BUTTON_RIGHT  1
#define KBD_BUTTON_DOWN   2
#define KBD_BUTTON_LEFT   3
//
#define BUTTON_PRESS      LOW
#define BUTTON_RELEASE    HIGH
#define BUTTON_DEBOUNCE   257
//
//    button debounce time is 20ms => button must be pressed 20ms contigouusly before being registered as PRESS, this number will be interpreted as number of subsequent calls to keyboard scan loop
#define BUTTON_DEBOUNCE_TIME 20
//
//    button event code, this event is sent when a keyboard event is detected
#define BUTTON_EVENT     384

extern void scanKeyboard(int para);

// end of KBD_RBPXPLR
#endif

//
// -------- KBD_GEN variant ---------------------------------------------------
//
#ifdef KBD_GEN

#ifdef WIRE_ENABLED
#define KBD_I2C
#else
#define KBD_DIG
#endif

/*
 * common definitions for both subtypes of GEN keyboard interfaces
 */
// 4 return (sense/input) lines from 4x4 keyboard matrix
#define ROWS 4
// 4 scan (drive/output) lines to 4x4 keyboard matrix
#define COLS 4

#define KBD_ROWMULTIPLIER 4

#define KBD_NUMKEYS (ROWS*COLS)

// end of KBD_GEN
#endif

// generic exported functions

extern void initKeyboard();
extern void setKeyFunction(int functionNumber, DFuncParPtr func, int functionParameter, String info);

// end of keyboard.h / _keyboard_h
#endif
