diff --git a/meson.build b/meson.build
index 5f4a2c57..8fe2cd1e 100644
--- a/meson.build
+++ b/meson.build
@@ -99,10 +99,10 @@ md380_src = src + ['openrtx/src/main.c',
'platform/mcu/STM32F4xx/drivers/gpio.c',
'platform/mcu/STM32F4xx/drivers/usb_vcom.c',
'platform/mcu/STM32F4xx/drivers/delays.c',
- 'platform/mcu/STM32F4xx/drivers/gpio.c',
'platform/mcu/CMSIS/Device/ST/STM32F4xx/Source/system_stm32f4xx.c',
'platform/drivers/display/HX83XX_md380.c',
'platform/targets/MD380/platform.c',
+ 'platform/targets/MD380/adc1.c',
'openrtx/src/graphics/graphics_rgb565.c',
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_c.c',
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M/os_cpu_a.s',
@@ -114,6 +114,7 @@ md380_def = def + {'STM32F40_41xxx': ''}
md380_inc = inc + ['platform/mcu/CMSIS/Include',
'platform/mcu/CMSIS/Device/ST/STM32F4xx/Include',
'platform/mcu/STM32F4xx',
+ 'platform/mcu/STM32F4xx/drivers',
'platform/mcu/STM32F4xx/drivers/usb',
'platform/targets/MD380',
'rtos/uC-OS3/Ports/ARM-Cortex-M/ARMv7-M',
diff --git a/platform/mcu/STM32F4xx/drivers/adc1.c b/platform/targets/MD380/adc1.c
similarity index 93%
rename from platform/mcu/STM32F4xx/drivers/adc1.c
rename to platform/targets/MD380/adc1.c
index b756302d..6a5f2a02 100644
--- a/platform/mcu/STM32F4xx/drivers/adc1.c
+++ b/platform/targets/MD380/adc1.c
@@ -15,8 +15,9 @@
* along with this program; if not, see *
***************************************************************************/
+#include
+#include "hwconfig.h"
#include "adc1.h"
-#include "gpio.h"
uint16_t measurements[4];
@@ -32,10 +33,10 @@ void adc1_init()
* - PA3: vox level
* - PB0: RSSI level
*/
- gpio_setMode(GPIOA, 0, INPUT_ANALOG);
- gpio_setMode(GPIOA, 1, INPUT_ANALOG);
- gpio_setMode(GPIOA, 3, INPUT_ANALOG);
- gpio_setMode(GPIOB, 0, INPUT_ANALOG);
+ gpio_setMode(AIN_VOLUME, INPUT_ANALOG);
+ gpio_setMode(AIN_VBAT, INPUT_ANALOG);
+ gpio_setMode(AIN_MIC, INPUT_ANALOG);
+ gpio_setMode(AIN_RSSI, INPUT_ANALOG);
/*
* ADC clock is APB2 frequency divided by 8, giving 10.5MHz.
@@ -89,7 +90,7 @@ void adc1_init()
ADC1->CR2 |= ADC_CR2_SWSTART;
}
-void adc1_shutdown()
+void adc1_terminate()
{
DMA2_Stream0->CR &= ~DMA_SxCR_EN;
ADC1->CR2 &= ADC_CR2_ADON;
diff --git a/platform/mcu/STM32F4xx/drivers/adc1.h b/platform/targets/MD380/adc1.h
similarity index 98%
rename from platform/mcu/STM32F4xx/drivers/adc1.h
rename to platform/targets/MD380/adc1.h
index 1a65c346..017d2182 100644
--- a/platform/mcu/STM32F4xx/drivers/adc1.h
+++ b/platform/targets/MD380/adc1.h
@@ -19,7 +19,6 @@
#define ADC1_H
#include
-#include "stm32f4xx.h"
/**
* Driver for ADC1, used to continuously sample the following channels:
@@ -45,7 +44,7 @@ void adc1_init();
* Turn off ADC1 (also gating off its clock) and disable DMA2 Stream 0.
* DMA2 clock is kept active.
*/
-void adc1_shutdown();
+void adc1_terminate();
/**
* Get current measurement of a given channel, mapped as below:
diff --git a/platform/targets/MD380/hwconfig.h b/platform/targets/MD380/hwconfig.h
index c6a040a3..11d46f8a 100644
--- a/platform/targets/MD380/hwconfig.h
+++ b/platform/targets/MD380/hwconfig.h
@@ -20,7 +20,7 @@
#ifndef HWCONFIG_H
#define HWCONFIG_H
-#include "stm32f4xx.h"
+#include
/* Screen dimensions */
#define SCREEN_WIDTH 160
@@ -43,4 +43,12 @@
#define LCD_BKLIGHT GPIOC,6
+#define GREEN_LED GPIOE,0
+#define RED_LED GPIOE,1
+
+#define AIN_VOLUME GPIOA,0
+#define AIN_VBAT GPIOA,1
+#define AIN_MIC GPIOA,3
+#define AIN_RSSI GPIOB,0
+
#endif
diff --git a/platform/targets/MD380/platform.c b/platform/targets/MD380/platform.c
index 10ed5d28..81a1c04d 100644
--- a/platform/targets/MD380/platform.c
+++ b/platform/targets/MD380/platform.c
@@ -17,13 +17,24 @@
* along with this program; if not, see *
***************************************************************************/
-#include
-#include "platform.h"
+#include
+#include
#include "hwconfig.h"
-#include "gpio.h"
+#include "adc1.h"
void platform_init()
{
+ /* Configure GPIOs */
+ 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, ... */
+ 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
@@ -42,18 +53,86 @@ void platform_init()
TIM8->CCR1 = 0;
TIM8->EGR = TIM_EGR_UG; /* Update registers */
TIM8->CR1 |= TIM_CR1_CEN; /* Start timer */
-
- /* Configure backlight GPIO, TIM8 is on AF3 */
- gpio_setMode(LCD_BKLIGHT, ALTERNATE);
- gpio_setAlternateFunction(LCD_BKLIGHT, 3);
}
void platform_terminate()
{
- /* Shut off backlight */
+ /* Shut down backlight */
gpio_setMode(LCD_BKLIGHT, OUTPUT);
gpio_clearPin(LCD_BKLIGHT);
+
+ gpio_clearPin(GREEN_LED);
+ gpio_clearPin(RED_LED);
+
+ /* Shut down timer */
RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN;
+
+ /* Shut down ADC */
+ adc1_terminate();
+}
+
+float platform_getVbat()
+{
+ return adc1_getMeasurement(0);
+}
+
+float platform_getMicLevel()
+{
+ return adc1_getMeasurement(2);
+}
+
+float platform_getVolumeLevel()
+{
+ return adc1_getMeasurement(3);
+}
+
+uint8_t platform_getChSelector()
+{
+ return 0.0f;
+}
+
+void platform_ledOn(led_t led)
+{
+ switch(led)
+ {
+ case GREEN:
+ gpio_setPin(GREEN_LED);
+ break;
+
+ case RED:
+ gpio_setPin(RED_LED);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void platform_ledOff(led_t led)
+{
+ switch(led)
+ {
+ case GREEN:
+ gpio_clearPin(GREEN_LED);
+ break;
+
+ case RED:
+ gpio_clearPin(RED_LED);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void platform_beepStart(uint16_t freq)
+{
+ (void) freq;
+}
+
+void platform_beepStop()
+{
+
}
void platform_setBacklightLevel(uint8_t level)