audio output working

pwm
erikkaashoek 3 years ago
parent 876d347d5e
commit a11057d4e7

@ -92,7 +92,7 @@ endif
ifeq ($(TARGET),F303) ifeq ($(TARGET),F303)
USE_FPU = hard USE_FPU = hard
USE_PROCESS_STACKSIZE = 0x380 USE_PROCESS_STACKSIZE = 0x480
USE_EXCEPTIONS_STACKSIZE = 0x200 USE_EXCEPTIONS_STACKSIZE = 0x200
endif endif

@ -64,7 +64,11 @@ static const ADCConversionGroup adcgrpcfgTouch = {
NULL, // adcerrorcallback_touch NULL, // adcerrorcallback_touch
// CFGR // CFGR
ADC_CFGR_EXTEN_0 // rising edge of external trigger ADC_CFGR_EXTEN_0 // rising edge of external trigger
| ADC_CFGR_EXTSEL_2 // EXT4 0x1000 event (TIM3_TRGO)
| ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_0 // EXT4 0x1001 event (TIM1_TRGO)
// | ADC_CFGR_EXTSEL_2 // EXT4 0x100 event (TIM3_TRGO)
| ADC_CFGR_AWD1EN, // Enable Analog watchdog check interrupt | ADC_CFGR_AWD1EN, // Enable Analog watchdog check interrupt
ADC_TR(0, TOUCH_THRESHOLD), // Analog watchdog threshold TR1, interrupt on touch press ADC_TR(0, TOUCH_THRESHOLD), // Analog watchdog threshold TR1, interrupt on touch press
{ADC_SMPR1_SMP_AN4(ADC_TOUCH_SMP_TIME), 0}, // SMPR[2] {ADC_SMPR1_SMP_AN4(ADC_TOUCH_SMP_TIME), 0}, // SMPR[2]

@ -162,7 +162,7 @@
PIN_MODE_INPUT(1U) | \ PIN_MODE_INPUT(1U) | \
PIN_MODE_INPUT(2U) | \ PIN_MODE_INPUT(2U) | \
PIN_MODE_INPUT(3U) | \ PIN_MODE_INPUT(3U) | \
PIN_MODE_INPUT(GPIO_SD_DAT2) | \ PIN_MODE_ALTERNATE(GPIO_SD_DAT2) | \
PIN_MODE_ANALOG(GPIOA_DAC2) | \ PIN_MODE_ANALOG(GPIOA_DAC2) | \
PIN_MODE_ANALOG(GPIOA_XP) | \ PIN_MODE_ANALOG(GPIOA_XP) | \
PIN_MODE_ANALOG(GPIOA_YP) | \ PIN_MODE_ANALOG(GPIOA_YP) | \
@ -242,7 +242,7 @@
PIN_AFIO_AF(1, 0) | \ PIN_AFIO_AF(1, 0) | \
PIN_AFIO_AF(2, 0) | \ PIN_AFIO_AF(2, 0) | \
PIN_AFIO_AF(3, 0) | \ PIN_AFIO_AF(3, 0) | \
PIN_AFIO_AF(GPIO_SD_DAT2, 0) | \ PIN_AFIO_AF(GPIO_SD_DAT2, 2) | \
PIN_AFIO_AF(5, 0) | \ PIN_AFIO_AF(5, 0) | \
PIN_AFIO_AF(6, 0) | \ PIN_AFIO_AF(6, 0) | \
PIN_AFIO_AF(7, 0)) PIN_AFIO_AF(7, 0))

@ -153,9 +153,9 @@
/* /*
* GPT driver system settings. * GPT driver system settings.
*/ */
#define STM32_GPT_USE_TIM1 FALSE #define STM32_GPT_USE_TIM1 TRUE
#define STM32_GPT_USE_TIM2 FALSE #define STM32_GPT_USE_TIM2 FALSE
#define STM32_GPT_USE_TIM3 TRUE #define STM32_GPT_USE_TIM3 FALSE
#define STM32_GPT_USE_TIM4 TRUE #define STM32_GPT_USE_TIM4 TRUE
#define STM32_GPT_TIM1_IRQ_PRIORITY 2 #define STM32_GPT_TIM1_IRQ_PRIORITY 2
#define STM32_GPT_TIM2_IRQ_PRIORITY 2 #define STM32_GPT_TIM2_IRQ_PRIORITY 2
@ -210,7 +210,7 @@
#define STM32_PWM_USE_ADVANCED FALSE #define STM32_PWM_USE_ADVANCED FALSE
#define STM32_PWM_USE_TIM1 FALSE #define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE #define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE #define STM32_PWM_USE_TIM3 TRUE
#define STM32_PWM_TIM1_IRQ_PRIORITY 3 #define STM32_PWM_TIM1_IRQ_PRIORITY 3
#define STM32_PWM_TIM2_IRQ_PRIORITY 3 #define STM32_PWM_TIM2_IRQ_PRIORITY 3
#define STM32_PWM_TIM3_IRQ_PRIORITY 3 #define STM32_PWM_TIM3_IRQ_PRIORITY 3

@ -115,7 +115,7 @@
* @brief Enables the PWM subsystem. * @brief Enables the PWM subsystem.
*/ */
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM FALSE #define HAL_USE_PWM TRUE
#endif #endif
/** /**

@ -2529,6 +2529,60 @@ THD_FUNCTION(myshellThread, p)
#pragma GCC pop_options #pragma GCC pop_options
#ifdef __PWM__
static void audio_toggle(void)
{
static volatile int h = 0;
if (h) {
DAC->DHR12R1 = 0;
h = 0;
} else {
DAC->DHR12R1 = 4095;
h = 1;
}
}
static PWMConfig pwmcfg = {
400000, /* 400kHz PWM clock frequency. */
100, /* Initial PWM frequency is 4kHz */
NULL,
{
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, audio_toggle},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
0,
0
};
#define PWM_TIMER PWMD3
#define PWM_CHANNEL 1 // Channel 2
void pwm_init(void) {
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(6)); // PA9
palSetPadMode(GPIOA, 4, PAL_MODE_ALTERNATE(2)); // PA4 Time 3 channel 2
pwmStart(&PWM_TIMER, &pwmcfg);
pwmEnableChannel(&PWM_TIMER, PWM_CHANNEL, PWM_PERCENTAGE_TO_WIDTH(&PWM_TIMER, 5000));
pwmEnableChannelNotification(&PWM_TIMER, PWM_CHANNEL);
}
void pwm_start(int f)
{
pwmcfg.frequency = f*100;
pwmStart(&PWM_TIMER, &pwmcfg);
// pwmChangePeriod(&PWM_TIMER, f);
pwmEnableChannel(&PWM_TIMER, PWM_CHANNEL, PWM_PERCENTAGE_TO_WIDTH(&PWM_TIMER, 5000));
}
void pwm_stop(void)
{
pwmDisableChannel(&PWM_TIMER, PWM_CHANNEL);
}
#endif
static const GPTConfig gpt4cfg = { static const GPTConfig gpt4cfg = {
8000000, // 8 MHz timer clock. 8000000, // 8 MHz timer clock.
NULL, // No callback NULL, // No callback
@ -2646,14 +2700,19 @@ int main(void)
spi_init(); spi_init();
PULSE PULSE
#ifdef __PWM__
pwm_init();
pwm_start(2000);
pwm_stop();
#endif
/* /*
* Set LCD display brightness (use DAC2 for control) * Set LCD display brightness (use DAC2 for control)
* Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual. * Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual.
*/ */
dac_init(); dac_init();
PULSE PULSE
DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2 // DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2
DAC->CR|= DAC_CR_EN2; // Use DAC: CH1 and CH2
#ifdef __LCD_BRIGHTNESS__ #ifdef __LCD_BRIGHTNESS__
lcd_setBrightness(DEFAULT_BRIGHTNESS); lcd_setBrightness(DEFAULT_BRIGHTNESS);
#endif #endif

@ -119,6 +119,11 @@
//#define __USE_FREQ_TABLE__ // Enable use table for frequency list //#define __USE_FREQ_TABLE__ // Enable use table for frequency list
#endif #endif
#ifdef __GUARD__
#define __PWM__
#endif
#ifdef TINYSA3 #ifdef TINYSA3
#define VARIANT(X,Y) (X) #define VARIANT(X,Y) (X)
#define DEFAULT_IF 433800000 #define DEFAULT_IF 433800000

@ -4872,14 +4872,14 @@ static bool sweep(bool break_on_operation)
if (current_guard > GUARDS_MAX) if (current_guard > GUARDS_MAX)
current_guard = 0; current_guard = 0;
} }
while(!setting.guards[current_guard].enabled); while(!(setting.guards[current_guard].enabled));
if (setting.guards[current_guard].end > setting.guards[current_guard].start) { if (setting.guards[current_guard].end > setting.guards[current_guard].start) {
set_sweep_frequency(ST_START, setting.guards[current_guard].start); set_sweep_frequency(ST_START, setting.guards[current_guard].start);
set_sweep_frequency(ST_STOP, setting.guards[current_guard].end); set_sweep_frequency(ST_STOP, setting.guards[current_guard].end);
set_rbw(8000); set_rbw(8000);
set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000); set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000);
} }
DAC->DHR12R1 = 0; pwm_stop();
} }
#endif #endif
@ -5213,7 +5213,7 @@ static volatile int dummy;
if (MODE_INPUT(setting.mode)) { if (MODE_INPUT(setting.mode)) {
#ifdef __GUARD__ #ifdef __GUARD__
if (setting.measurement == M_GUARD && RSSI > setting.guards[current_guard].level) { if (setting.measurement == M_GUARD && RSSI > setting.guards[current_guard].level) {
DAC->DHR12R1 = 4095; pwm_start(4000);
} }
#endif #endif
for (int t=0; t<TRACES_MAX;t++) { // Calculate all traces for (int t=0; t<TRACES_MAX;t++) { // Calculate all traces
@ -5333,7 +5333,7 @@ static volatile int dummy;
goto sweep_again; // Keep repeating sweep loop till user aborts by input goto sweep_again; // Keep repeating sweep loop till user aborts by input
} }
// --------------- check if maximum is above trigger level ----------------- // --------------- check if maximum is above trigger level -----------------
#ifdef __GUARD__ #ifdef __GUARD__XX
if (setting.measurement == M_GUARD) { if (setting.measurement == M_GUARD) {
if (measured[peakTrace][peakIndex] < setting.guards[current_guard].level) if (measured[peakTrace][peakIndex] < setting.guards[current_guard].level)
goto again; goto again;

@ -349,8 +349,8 @@ static void touch_init(void){
// Prepare pin for measure touch event // Prepare pin for measure touch event
touch_prepare_sense(); touch_prepare_sense();
// Start touch interrupt, used timer_3 ADC check threshold: // Start touch interrupt, used timer_3 ADC check threshold:
gptStart(&GPTD3, &gpt3cfg); // Init timer 3 gptStart(&GPTD1, &gpt3cfg); // Init timer 3
gptStartContinuous(&GPTD3, 10); // Start timer 3 vs timer 10 interval gptStartContinuous(&GPTD1, 10); // Start timer 3 vs timer 10 interval
touch_start_watchdog(); // Start ADC watchdog (measure by timer 3 interval and trigger interrupt if touch pressed) touch_start_watchdog(); // Start ADC watchdog (measure by timer 3 interval and trigger interrupt if touch pressed)
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.