From fed1146690d1e790c4be17e97e9dfb47f8385c93 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 24 Oct 2020 19:24:57 +0200 Subject: [PATCH] Adding channel selector and PTT to MD-380 platform API --- platform/targets/MD380/hwconfig.h | 14 ++++++++++++-- platform/targets/MD380/platform.c | 30 +++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/platform/targets/MD380/hwconfig.h b/platform/targets/MD380/hwconfig.h index 11d46f8a..3b11210d 100644 --- a/platform/targets/MD380/hwconfig.h +++ b/platform/targets/MD380/hwconfig.h @@ -26,7 +26,7 @@ #define SCREEN_WIDTH 160 #define SCREEN_HEIGHT 128 -/* Defines for GPIO control, really ugly but useful. */ +/* Display */ #define LCD_D0 GPIOD,14 #define LCD_D1 GPIOD,15 #define LCD_D2 GPIOD,0 @@ -40,15 +40,25 @@ #define LCD_CS GPIOD,6 #define LCD_RS GPIOD,12 #define LCD_RST GPIOD,13 - #define LCD_BKLIGHT GPIOC,6 +/* Signalling LEDs */ #define GREEN_LED GPIOE,0 #define RED_LED GPIOE,1 +/* Analog inputs */ #define AIN_VOLUME GPIOA,0 #define AIN_VBAT GPIOA,1 #define AIN_MIC GPIOA,3 #define AIN_RSSI GPIOB,0 +/* Channel selection rotary encoder */ +#define CH_SELECTOR_0 GPIOE,14 +#define CH_SELECTOR_1 GPIOE,15 +#define CH_SELECTOR_2 GPIOB,10 +#define CH_SELECTOR_3 GPIOB,11 + +/* Push-to-talk switch */ +#define PTT_SW GPIOE,11 + #endif diff --git a/platform/targets/MD380/platform.c b/platform/targets/MD380/platform.c index 40404b29..d4d35c4d 100644 --- a/platform/targets/MD380/platform.c +++ b/platform/targets/MD380/platform.c @@ -28,17 +28,28 @@ void platform_init() gpio_setMode(GREEN_LED, OUTPUT); gpio_setMode(RED_LED, OUTPUT); - /* Backlight pin connected to TIM8 CR1 */ gpio_setMode(LCD_BKLIGHT, ALTERNATE); gpio_setAlternateFunction(LCD_BKLIGHT, 3); - /* Initialise ADC1, for vbat, RSSI, ... */ + gpio_setMode(CH_SELECTOR_0, INPUT); + gpio_setMode(CH_SELECTOR_1, INPUT); + gpio_setMode(CH_SELECTOR_2, INPUT); + gpio_setMode(CH_SELECTOR_3, INPUT); + + gpio_setMode(PTT_SW, INPUT); + + /* + * Initialise ADC1, for vbat, RSSI, ... + * Configuration of corresponding GPIOs in analog input mode is done inside + * the driver. + */ adc1_init(); /* * Configure TIM8 for backlight PWM: Fpwm = 100kHz, 8 bit of resolution * APB2 freq. is 84MHz, then: PSC = 327 to have Ftick = 256.097kHz * With ARR = 256, Fpwm is 100kHz; + * Backlight pin is connected to TIM8 CR1. */ RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; TIM8->ARR = 255; @@ -61,6 +72,7 @@ void platform_terminate() gpio_setMode(LCD_BKLIGHT, OUTPUT); gpio_clearPin(LCD_BKLIGHT); + /* Shut down LEDs */ gpio_clearPin(GREEN_LED); gpio_clearPin(RED_LED); @@ -88,12 +100,19 @@ float platform_getVolumeLevel() uint8_t platform_getChSelector() { - return 0.0f; + static const uint8_t rsPositions[] = { 11, 14, 10, 15, 6, 3, 7, 2, 12, 13, + 9, 16, 5, 4, 8, 1 }; + int pos = gpio_readPin(CH_SELECTOR_0) + | (gpio_readPin(CH_SELECTOR_1) << 1) + | (gpio_readPin(CH_SELECTOR_2) << 2) + | (gpio_readPin(CH_SELECTOR_3) << 3); + return rsPositions[pos]; } bool platform_getPttStatus() { - return false; + /* PTT line has a pullup resistor with PTT switch closing to ground */ + return (gpio_readPin(PTT_SW) == 0) ? true : false; } void platform_ledOn(led_t led) @@ -132,12 +151,13 @@ void platform_ledOff(led_t led) void platform_beepStart(uint16_t freq) { + /* TODO */ (void) freq; } void platform_beepStop() { - + /* TODO */ } void platform_setBacklightLevel(uint8_t level)