Switch driver, key/trim driver

This commit is contained in:
Richard Li
2025-01-24 19:00:12 +01:00
committed by Malte Langermann
parent 7dcb4b3d9a
commit 276f10e7bb
9 changed files with 247 additions and 42 deletions
+55 -7
View File
@@ -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;
}