Switch driver, key/trim driver
This commit is contained in:
committed by
Malte Langermann
parent
7dcb4b3d9a
commit
276f10e7bb
@@ -46,22 +46,22 @@ __weak SwitchHwPos boardSwitchGetPosition(SwitchCategory cat, uint8_t idx)
|
||||
return stm32_switch_get_position(sw);
|
||||
}
|
||||
|
||||
const char* boardSwitchGetName(SwitchCategory cat, uint8_t idx)
|
||||
__weak const char* boardSwitchGetName(SwitchCategory cat, uint8_t idx)
|
||||
{
|
||||
return _switch_offsets[cat][idx].name;
|
||||
}
|
||||
|
||||
SwitchHwType boardSwitchGetType(SwitchCategory cat, uint8_t idx)
|
||||
__weak SwitchHwType boardSwitchGetType(SwitchCategory cat, uint8_t idx)
|
||||
{
|
||||
return _switch_offsets[cat][idx].type;
|
||||
}
|
||||
|
||||
uint8_t boardGetMaxSwitches() { return n_switches; }
|
||||
uint8_t boardGetMaxFctSwitches() { return n_fct_switches; }
|
||||
__weak uint8_t boardGetMaxSwitches() { return n_switches; }
|
||||
__weak uint8_t boardGetMaxFctSwitches() { return n_fct_switches; }
|
||||
|
||||
swconfig_t boardSwitchGetDefaultConfig() { return _switch_default_config; }
|
||||
__weak swconfig_t boardSwitchGetDefaultConfig() { return _switch_default_config; }
|
||||
|
||||
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
|
||||
__weak switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
|
||||
{
|
||||
// TODO: find a solution for FLEX switches so they can be displayed on main view
|
||||
if (idx >= DIM(_switch_display)) return {0, 0};
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
#include "libopenui.h"
|
||||
#include "edgetx.h"
|
||||
|
||||
#if defined(PCBPL18)
|
||||
#if defined(RADIO_NB4P)
|
||||
static const uint8_t _trimMap[MAX_TRIMS * 2] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
#elif defined(PCBPL18)
|
||||
static const uint8_t _trimMap[MAX_TRIMS * 2] = {8, 9, 10, 11, 12, 13, 14, 15,
|
||||
2, 3, 4, 5, 0, 1, 6, 7};
|
||||
#else
|
||||
|
||||
@@ -133,6 +133,14 @@ if(ROTARY_ENCODER)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(PCBREV STREQUAL NB4P)
|
||||
set(BOARD_SPECIFIC_SRC
|
||||
${TARGET_SRC_DIR}/switch_driver.cpp
|
||||
)
|
||||
#else()
|
||||
# set(BOARD_SPECIFIC_SRC)
|
||||
endif()
|
||||
|
||||
# Bootloader board library
|
||||
add_library(board_bl OBJECT EXCLUDE_FROM_ALL
|
||||
${BOARD_COMMON_SRC}
|
||||
@@ -144,6 +152,7 @@ set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:board_bl>)
|
||||
# Firmware board library
|
||||
add_library(board OBJECT EXCLUDE_FROM_ALL
|
||||
${BOARD_COMMON_SRC}
|
||||
${BOARD_SPECIFIC_SRC}
|
||||
${TARGET_SRC_DIR}/${TOUCH_DRIVER}
|
||||
${TARGET_SRC_DIR}/battery_driver.cpp
|
||||
targets/common/arm/stm32/audio_dac_driver.cpp
|
||||
@@ -159,7 +168,9 @@ add_library(board OBJECT EXCLUDE_FROM_ALL
|
||||
targets/common/arm/stm32/spi_flash.cpp
|
||||
targets/common/arm/stm32/diskio_spi_flash.cpp
|
||||
drivers/frftl.cpp
|
||||
|
||||
)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:board>)
|
||||
|
||||
set(FIRMWARE_SRC
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
// PL18/PL18EV only has virtual keys via trim buttons
|
||||
// #define KEYS_GPIO_PIN_PGUP /* for activating PGUP in keys diagnose screen */
|
||||
|
||||
#if !defined(RADIO_NB4P)
|
||||
// Trims
|
||||
#define TRIMS_GPIO_REG_LHL
|
||||
#define TRIMS_GPIO_PIN_LHL
|
||||
@@ -65,6 +64,7 @@
|
||||
#define TRIMS_GPIO_REG_LVU
|
||||
#define TRIMS_GPIO_PIN_LVU
|
||||
|
||||
#if !defined(RADIO_NB4P)
|
||||
#define TRIMS_GPIO_REG_RHL
|
||||
#define TRIMS_GPIO_PIN_RHL
|
||||
|
||||
@@ -312,24 +312,28 @@
|
||||
#define ADC_GPIO_PIN_STICK_ST LL_GPIO_PIN_2 // PA.02
|
||||
#define ADC_CHANNEL_STICK_TH LL_ADC_CHANNEL_3 // ADC123_IN3 -> ADC1_IN3
|
||||
#define ADC_CHANNEL_STICK_ST LL_ADC_CHANNEL_2 // ADC123_IN2 -> ADC1_IN2
|
||||
#define ADC_GPIO_PIN_SWA LL_GPIO_PIN_1 //PC.01
|
||||
#define ADC_GPIO_SWB GPIOC
|
||||
#define ADC_GPIO_PIN_SWB LL_GPIO_PIN_0 //PC.00
|
||||
#define ADC_CHANNEL_SWA LL_ADC_CHANNEL_11 // ADC123_IN11 -> ADC1_IN11
|
||||
#define ADC_CHANNEL_SWB LL_ADC_CHANNEL_10 // ADC123_IN10 -> ADC1_IN10
|
||||
// #define ADC_GPIO_PIN_SWA LL_GPIO_PIN_1 //PC.01
|
||||
#define ADC_GPIO_EXT2 GPIOC
|
||||
// #define ADC_GPIO_PIN_SWB LL_GPIO_PIN_0 //PC.00
|
||||
// #define ADC_CHANNEL_SWA LL_ADC_CHANNEL_11 // ADC123_IN11 -> ADC1_IN11
|
||||
// #define ADC_CHANNEL_SWB LL_ADC_CHANNEL_10 // ADC123_IN10 -> ADC1_IN10
|
||||
#define ADC_GPIO_PIN_POT1 LL_GPIO_PIN_7 // PA.07
|
||||
#define ADC_GPIO_PIN_POT2 LL_GPIO_PIN_2 // PC.02
|
||||
#define ADC_GPIO_PIN_POT3 LL_GPIO_PIN_6 // PA.06
|
||||
#define ADC_GPIO_PIN_POT4 LL_GPIO_PIN_4 // PC.04
|
||||
#define ADC_GPIO_PIN_EXT1 LL_GPIO_PIN_1 // PC.01 (SW1)
|
||||
#define ADC_GPIO_PIN_EXT2 LL_GPIO_PIN_0 // PC.00 (SW2 SW3)
|
||||
#define ADC_GPIO_PIN_EXT3 LL_GPIO_PIN_6 // PA.06 (TR1)
|
||||
#define ADC_GPIO_PIN_EXT4 LL_GPIO_PIN_4 // PC.04 (TR2)
|
||||
#define ADC_GPIO_PIN_BATT LL_GPIO_PIN_5 // PC.05
|
||||
#define ADC_CHANNEL_POT1 LL_ADC_CHANNEL_7 // ADC12_IN7 -> ADC1_IN7
|
||||
#define ADC_CHANNEL_POT2 LL_ADC_CHANNEL_12 // ADC123_IN12 -> ADC1_IN12
|
||||
#define ADC_CHANNEL_POT3 LL_ADC_CHANNEL_6 // ADC12_IN6 -> ADC1_IN6
|
||||
#define ADC_CHANNEL_POT4 LL_ADC_CHANNEL_14 // ADC12_IN14 -> ADC1_IN14
|
||||
#define ADC_CHANNEL_EXT1 LL_ADC_CHANNEL_11 // ADC123_IN11 -> ADC1_IN11
|
||||
#define ADC_CHANNEL_EXT2 LL_ADC_CHANNEL_10 // ADC123_IN10 -> ADC1_IN10
|
||||
#define ADC_CHANNEL_EXT3 LL_ADC_CHANNEL_6 // ADC12_IN6 -> ADC1_IN6
|
||||
#define ADC_CHANNEL_EXT4 LL_ADC_CHANNEL_14 // ADC12_IN14 -> ADC1_IN14
|
||||
#define ADC_CHANNEL_BATT LL_ADC_CHANNEL_15 // ADC12_IN15 -> ADC1_IN15
|
||||
#define ADC_CHANNEL_RTC_BAT LL_ADC_CHANNEL_VBAT // ADC1_IN18
|
||||
#define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_TH | ADC_GPIO_PIN_STICK_ST | ADC_GPIO_PIN_POT1 | ADC_GPIO_PIN_POT3)
|
||||
#define ADC_GPIOC_PINS (ADC_GPIO_PIN_SWA | ADC_GPIO_PIN_SWB | ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_POT4 | ADC_GPIO_PIN_BATT)
|
||||
#define ADC_GPIOA_PINS (ADC_GPIO_PIN_STICK_TH | ADC_GPIO_PIN_STICK_ST | ADC_GPIO_PIN_POT1 | ADC_GPIO_PIN_EXT3)
|
||||
#define ADC_GPIOC_PINS (ADC_GPIO_PIN_EXT1 | ADC_GPIO_PIN_EXT2 | ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_EXT4 | ADC_GPIO_PIN_BATT)
|
||||
|
||||
#define ADC_MAIN ADC1
|
||||
#define ADC_SAMPTIME LL_ADC_SAMPLINGTIME_28CYCLES
|
||||
|
||||
@@ -28,19 +28,42 @@
|
||||
#include "delays_driver.h"
|
||||
#include "keys.h"
|
||||
|
||||
#if !defined(BOOT)
|
||||
#include "hal/adc_driver.h"
|
||||
#endif
|
||||
|
||||
#define BOOTLOADER_KEYS 0x42
|
||||
|
||||
/* The output bit-order has to be:
|
||||
0 LHL STD (Left equals down)
|
||||
1 LHR STU
|
||||
2 LVD THD
|
||||
3 LVU THU
|
||||
*/
|
||||
|
||||
enum PhysicalTrims
|
||||
{
|
||||
STD = 0,
|
||||
STU,
|
||||
THD = 2,
|
||||
THU,
|
||||
/* TR2L = 4,
|
||||
TR2R,
|
||||
TR2D = 8,
|
||||
TR2U,*/
|
||||
};
|
||||
|
||||
void keysInit()
|
||||
{
|
||||
#if defined(BOOT)
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = ADC_GPIO_PIN_SWB;
|
||||
pinInit.Pin = ADC_GPIO_PIN_EXT2;
|
||||
pinInit.Mode = LL_GPIO_MODE_ANALOG;
|
||||
pinInit.Pull = LL_GPIO_PULL_NO;
|
||||
stm32_gpio_enable_clock(ADC_GPIO_SWB);
|
||||
LL_GPIO_Init(ADC_GPIO_SWB, &pinInit);
|
||||
stm32_gpio_enable_clock(ADC_GPIO_EXT2);
|
||||
LL_GPIO_Init(ADC_GPIO_EXT2, &pinInit);
|
||||
|
||||
// Init ADC clock
|
||||
uint32_t adc_idx = (((uint32_t) ADC_MAIN) - ADC1_BASE) / 0x100UL;
|
||||
@@ -79,8 +102,8 @@ void keysInit()
|
||||
uint16_t _adcRead()
|
||||
{
|
||||
// Configure ADC channel
|
||||
LL_ADC_REG_SetSequencerRanks(ADC_MAIN, LL_ADC_REG_RANK_1, ADC_CHANNEL_SWB);
|
||||
LL_ADC_SetChannelSamplingTime(ADC_MAIN, ADC_CHANNEL_SWB, LL_ADC_SAMPLINGTIME_3CYCLES);
|
||||
LL_ADC_REG_SetSequencerRanks(ADC_MAIN, LL_ADC_REG_RANK_1, ADC_CHANNEL_EXT2);
|
||||
LL_ADC_SetChannelSamplingTime(ADC_MAIN, ADC_CHANNEL_EXT2, LL_ADC_SAMPLINGTIME_3CYCLES);
|
||||
|
||||
// Start ADC conversion
|
||||
LL_ADC_REG_StartConversionSWStart(ADC_MAIN);
|
||||
@@ -101,9 +124,10 @@ uint32_t readKeys()
|
||||
#if defined(BOOT)
|
||||
uint16_t value = _adcRead();
|
||||
if (value >= 3584)
|
||||
result |= 1 << KEY_ENTER;
|
||||
else if (value < 512)
|
||||
result |= 1 << KEY_EXIT;
|
||||
else if (value < 512)
|
||||
result |= 1 << KEY_ENTER;
|
||||
#else
|
||||
#endif
|
||||
|
||||
return result;
|
||||
@@ -117,6 +141,30 @@ uint32_t readTrims()
|
||||
uint16_t value = _adcRead();
|
||||
if (value >= 1536 && value < 2560)
|
||||
result = BOOTLOADER_KEYS;
|
||||
#else
|
||||
uint16_t tr1Val = getAnalogValue(6);
|
||||
uint16_t tr2Val = getAnalogValue(7);
|
||||
if (tr1Val < 500) // Physical TR1 Left
|
||||
// result |= 1 << TR1L;
|
||||
;
|
||||
else if (tr1Val < 1500) // Physical TR1 Up
|
||||
result |= 1 << STD;
|
||||
else if (tr1Val < 2500) // Physical TR1 Right
|
||||
// result |= 1 << TR1R;
|
||||
;
|
||||
else if (tr1Val < 3500) // Physical TR1 Down
|
||||
result |= 1 << STU;
|
||||
if (tr2Val < 500) // Physical TR2 Left
|
||||
// result |= 1 << TR2L;
|
||||
;
|
||||
else if (tr2Val < 1500) // Physical TR2 Up
|
||||
result |= 1 << THD;
|
||||
else if (tr2Val < 2500) // Physical TR2 Right
|
||||
// result |= 1 << TR2R;
|
||||
;
|
||||
else if (tr2Val < 3500) // Physical TR2 Down
|
||||
result |= 1 << THU;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/switch_driver.h"
|
||||
#include "stm32_switch_driver.h"
|
||||
//#include "stm32_gpio_driver.h"
|
||||
|
||||
#include "definitions.h"
|
||||
#include "opentx_constants.h"
|
||||
#include "myeeprom.h"
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define __weak __attribute__((weak))
|
||||
|
||||
static const stm32_switch_t _switch_defs[] = {
|
||||
{
|
||||
"S1A",
|
||||
nullptr, 0,
|
||||
nullptr, 0,
|
||||
SWITCH_HW_2POS, 0
|
||||
},
|
||||
{
|
||||
"S1B",
|
||||
nullptr, 0,
|
||||
nullptr, 0,
|
||||
SWITCH_HW_2POS, 0
|
||||
},
|
||||
{
|
||||
"S2",
|
||||
nullptr, 0,
|
||||
nullptr, 0,
|
||||
SWITCH_HW_2POS, 0
|
||||
},
|
||||
{
|
||||
"S3",
|
||||
nullptr, 0,
|
||||
nullptr, 0,
|
||||
SWITCH_HW_2POS, 0
|
||||
}
|
||||
};
|
||||
|
||||
constexpr uint8_t n_switches = 4;
|
||||
constexpr uint8_t n_fct_switches = 0;
|
||||
|
||||
constexpr swconfig_t _switch_default_config = (swconfig_t)0
|
||||
| ((swconfig_t)SWITCH_2POS << (0 * SW_CFG_BITS))
|
||||
| ((swconfig_t)SWITCH_2POS << (1 * SW_CFG_BITS))
|
||||
| ((swconfig_t)SWITCH_2POS << (2 * SW_CFG_BITS))
|
||||
| ((swconfig_t)SWITCH_2POS << (3 * SW_CFG_BITS))
|
||||
;
|
||||
|
||||
const switch_display_pos_t _switch_display[] = {
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
SwitchHwPos boardSwitchGetPosition(uint8_t cat, uint8_t idx)
|
||||
{
|
||||
if (idx <= 1) {
|
||||
uint16_t swVal = getAnalogValue(4);
|
||||
if (idx == 0 && (swVal < 512 || (swVal >= 1536 && swVal < 2560))) {
|
||||
return SWITCH_HW_DOWN;
|
||||
}
|
||||
if (idx == 1 && (swVal >= 3584 || (swVal >= 1536 && swVal < 2560))) {
|
||||
return SWITCH_HW_DOWN;
|
||||
}
|
||||
} else if (idx <= 3) {
|
||||
uint16_t swVal = getAnalogValue(5);
|
||||
if (idx == 3 && (swVal < 512 || (swVal >= 1536 && swVal < 2560))) {
|
||||
return SWITCH_HW_DOWN;
|
||||
}
|
||||
if (idx == 2 && (swVal >= 3584 || (swVal >= 1536 && swVal < 2560))) {
|
||||
return SWITCH_HW_DOWN;
|
||||
}
|
||||
}
|
||||
return SWITCH_HW_UP;
|
||||
}
|
||||
|
||||
const char* boardSwitchGetName(uint8_t cat, uint8_t idx)
|
||||
{
|
||||
return _switch_defs[idx].name;
|
||||
}
|
||||
|
||||
SwitchHwType boardSwitchGetType(uint8_t cat, uint8_t idx)
|
||||
{
|
||||
return _switch_defs[idx].type;
|
||||
}
|
||||
|
||||
uint8_t boardGetMaxSwitches() { return n_switches; }
|
||||
uint8_t boardGetMaxFctSwitches() { return n_fct_switches; }
|
||||
|
||||
swconfig_t boardSwitchGetDefaultConfig() { return _switch_default_config; }
|
||||
|
||||
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
|
||||
{
|
||||
// TODO: find a solution for FLEX switches so they can be displayed on main view
|
||||
if (idx >= DIM(_switch_display)) return {0, 0};
|
||||
|
||||
return _switch_display[idx];
|
||||
}
|
||||
@@ -708,19 +708,33 @@ LEGACY_NAMES = [
|
||||
"short_label": "2",
|
||||
"description": "Potentiometer 2"
|
||||
},
|
||||
"P3": {
|
||||
"yaml": "POT3",
|
||||
"lua": "s3",
|
||||
"label": "S3",
|
||||
"short_label": "3",
|
||||
"description": "Analog 3"
|
||||
"EXT1": {
|
||||
"yaml": "EXT1",
|
||||
"lua": "ext1",
|
||||
"label": "EXT1",
|
||||
"short_label": "E1",
|
||||
"description": "Ext 1"
|
||||
},
|
||||
"P4": {
|
||||
"yaml": "POT4",
|
||||
"lua": "s4",
|
||||
"label": "S4",
|
||||
"short_label": "4",
|
||||
"description": "Analog 4"
|
||||
"EXT2": {
|
||||
"yaml": "EXT2",
|
||||
"lua": "ext2",
|
||||
"label": "EXT2",
|
||||
"short_label": "E2",
|
||||
"description": "Ext 2"
|
||||
},
|
||||
"EXT3": {
|
||||
"yaml": "EXT3",
|
||||
"lua": "ext3",
|
||||
"label": "EXT3",
|
||||
"short_label": "E3",
|
||||
"description": "Ext 3"
|
||||
},
|
||||
"EXT4": {
|
||||
"yaml": "EXT4",
|
||||
"lua": "ext4",
|
||||
"label": "EXT4",
|
||||
"short_label": "E4",
|
||||
"description": "Ext 4"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -42,8 +42,10 @@ POT_CONFIG = {
|
||||
"nb4p": {
|
||||
"P1": {"default": "POT"},
|
||||
"P2": {"default": "POT"},
|
||||
"P3": {"default": "POT"},
|
||||
"P4": {"default": "POT"}
|
||||
"EXT1": {"default": "MULTIPOS"},
|
||||
"EXT2": {"default": "MULTIPOS"},
|
||||
"EXT3": {"default": "MULTIPOS"},
|
||||
"EXT4": {"default": "MULTIPOS"}
|
||||
},
|
||||
"v12": {
|
||||
"P1": {"default": "POT_CENTER"},
|
||||
|
||||
@@ -66,8 +66,10 @@ SWITCH_CONFIG = {
|
||||
"SJ": { "default": "3POS" }
|
||||
},
|
||||
"nb4p": {
|
||||
"SA": { "default": "3POS" },
|
||||
"SB": { "default": "3POS" }
|
||||
"S1A": { "default": "TOGGLE" },
|
||||
"S1B": { "default": "TOGGLE" },
|
||||
"S2" : { "default": "TOGGLE" },
|
||||
"S3" : { "default": "TOGGLE" }
|
||||
},
|
||||
"lr3pro": {
|
||||
# left side
|
||||
|
||||
Reference in New Issue
Block a user