Support for palmtop mic keys in MD9600 keyboard driver

This commit is contained in:
Silvano Seva 2021-04-10 10:50:23 +02:00
parent 2d3d932111
commit db6b427513
2 changed files with 99 additions and 1 deletions

View File

@ -20,12 +20,60 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <interfaces/gpio.h>
#include <interfaces/delays.h>
#include <interfaces/keyboard.h>
#include <interfaces/platform.h>
#include <ADC1_MDx.h>
#include "hwconfig.h"
/**
* \internal
* Helper function which compares two voltages and tells if they're equal within
* a 200mV range.
*
* @param voltage: voltage to be compared against reference, in mV.
* @param reference: reference voltage for comparison, in mV.
* @return true if voltage is equal to reference ± 200mV, false otherwise.
*/
bool _compareVoltages(const int voltage, const int reference)
{
int difference = voltage - reference;
if(abs(difference) <= 200) return true;
return false;
}
/*
* Mapping of palmtop mic buttons:
*
* +-------+-------+-------+-------+
* | Col 0 | Col 1 | Col 2 | Col 3 |
* +-------+-------+-------+-------+-------+
* | Row 0 | 1 | 2 | 3 | A |
* +-------+-------+-------+-------+-------+
* | Row 1 | 4 | 5 | 6 | B |
* +-------+-------+-------+-------+-------+
* | Row 2 | 7 | 8 | 9 | C |
* +-------+-------+-------+-------+-------+
* | Row 3 | * | 0 | # | D |
* +-------+-------+-------+-------+-------+
* | Row 4 | | A/B | UP | DOWN |
* +-------+-------+-------+-------+-------+
*
*/
static const uint32_t micKeymap[5][4] =
{
{ KEY_1, KEY_2, KEY_3, KEY_F1 },
{ KEY_4, KEY_5, KEY_6, KEY_F2 },
{ KEY_7, KEY_8, KEY_9, KEY_F3 },
{KEY_STAR, KEY_0, KEY_HASH, KEY_F4 },
{ 0 , KEY_F5, KEY_UP, KEY_DOWN}
};
void kbd_init()
{
gpio_setMode(KB_COL1, INPUT_PULL_UP);
@ -109,5 +157,54 @@ keyboard_t kbd_getKeys()
if(gpio_readPin(KB_COL4) == 0) keys |= KEY_F2;
gpio_setPin(KB_ROW3);
/*
* Mapping of palmtop mic row/coloumn voltages:
* +-------+-------+-------+-------+
* | Col 0 | Col 1 | Col 2 | Col 3 |
* +-------+-------+-------+-------+
* | 700mV | 1300mV| 1900mV| 2600mV|
* +-------+--------+-------+-------+-------+-------+
* | Row 0 | 2600mV |
* +-------+--------+
* | Row 1 | 2100mV |
* +-------+--------+
* | Row 2 | 1500mV |
* +-------+--------+
* | Row 3 | 1000mV |
* +-------+--------+
* | Row 4 | 500mV |
* +-------+--------+
*
*/
/* Retrieve row/coloumn voltage measurements. */
uint16_t row = ((uint16_t) adc1_getMeasurement(ADC_SW2_CH) + 0.5f);
uint16_t col = ((uint16_t) adc1_getMeasurement(ADC_SW1_CH) + 0.5f);
/* Map row voltage to row index. */
uint8_t rowIdx = 0xFF;
if(_compareVoltages(row, 2600)) rowIdx = 0;
if(_compareVoltages(row, 2100)) rowIdx = 1;
if(_compareVoltages(row, 1500)) rowIdx = 2;
if(_compareVoltages(row, 1000)) rowIdx = 3;
if(_compareVoltages(row, 500)) rowIdx = 4;
/* Map col voltage to col index. */
uint8_t colIdx = 0xFF;
if(_compareVoltages(col, 700)) colIdx = 0;
if(_compareVoltages(col, 1300)) colIdx = 1;
if(_compareVoltages(col, 1900)) colIdx = 2;
if(_compareVoltages(col, 2600)) colIdx = 3;
/*
* Get corresponding key.
* Having rowIdx or colIdx equal to 0xFF means that no button on the palmtop
* key is pressed.
*/
if((rowIdx != 0xFF) && (colIdx != 0xFF))
{
keys |= micKeymap[rowIdx][colIdx];
}
return keys;
}

View File

@ -41,6 +41,7 @@ void platform_init()
gpio_setMode(PTT_SW, INPUT);
gpio_setMode(PWR_SW, OUTPUT);
gpio_setPin(PWR_SW);
/*
* Initialise ADC1, for vbat, RSSI, ...
@ -140,7 +141,7 @@ float platform_getVolumeLevel()
return 0.0f;
}
uint8_t platform_getChSelector()
int8_t platform_getChSelector()
{
static const uint8_t rsPositions[] = { 1, 4, 2, 3};
int pos = gpio_readPin(CH_SELECTOR_0)