diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-03-30 19:11:29 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-03-30 19:11:29 +1000 |
commit | fb8d159749daa8aefa75615d2f8a6cca2fac9ec0 (patch) | |
tree | 132c56a8db4e46a6bec3e0d9057ca8eeaed03090 /boards/base/Olimex-SAM7EX256-GE8/gaudio_play_board.h | |
parent | 04f03ea71da1337c501b598c6038afaf0216fed8 (diff) | |
download | uGFX-fb8d159749daa8aefa75615d2f8a6cca2fac9ec0.tar.gz uGFX-fb8d159749daa8aefa75615d2f8a6cca2fac9ec0.tar.bz2 uGFX-fb8d159749daa8aefa75615d2f8a6cca2fac9ec0.zip |
Turn on PWM audio output for Olimex SAM7EX256 board.
Diffstat (limited to 'boards/base/Olimex-SAM7EX256-GE8/gaudio_play_board.h')
-rw-r--r-- | boards/base/Olimex-SAM7EX256-GE8/gaudio_play_board.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/boards/base/Olimex-SAM7EX256-GE8/gaudio_play_board.h b/boards/base/Olimex-SAM7EX256-GE8/gaudio_play_board.h new file mode 100644 index 00000000..bbbc48c6 --- /dev/null +++ b/boards/base/Olimex-SAM7EX256-GE8/gaudio_play_board.h @@ -0,0 +1,75 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef GAUDIO_PLAY_BOARD_H +#define GAUDIO_PLAY_BOARD_H + +/* Our timer callback */ +static void gptcallback(GPTDriver *gptp) { + (void) gptp; + gaudio_play_pwm_timer_callbackI(); +} + +/* PWM configuration structure. The speaker is on PWM0/PB19 ie PWM1/PIN1 in ChibiOS speak */ +static PWMConfig pwmcfg = { + 1000000, /* 1 MHz PWM clock frequency. Ignored as we are using PWM_MCK_DIV_n */ + 1024, /* PWM period is 1024 cycles (10 bits). */ + 0, + { + {PWM_MCK_DIV_1 | PWM_OUTPUT_CENTER | PWM_OUTPUT_ACTIVE_HIGH | PWM_OUTPUT_PIN1 | PWM_DISABLEPULLUP_PIN1, 0}, + }, +}; + +/* Timer configuration structure. We use Timer 2 (TC1) */ +static GPTConfig gptcfg = { + 8192, // frequency + gptcallback, // callback + GPT_CLOCK_FREQUENCY, // clocksource + GPT_GATE_NONE, // clockgate + GPT_TRIGGER_NONE, // trigger +}; + +static uint16_t lastvalue; + +static bool gaudio_play_pwm_setup(uint32_t frequency, ArrayDataFormat format) { + if (format == ARRAY_DATA_10BITUNSIGNED) + pwmcfg.period = 1024; + else if (format == ARRAY_DATA_8BITUNSIGNED) + pwmcfg.period = 256; + else + return FALSE; + gptcfg.frequency = frequency; + return TRUE; +} + +static void gaudio_play_pwm_start(void) { + /* Start the PWM */ + pwmStart(&PWMD1, &pwmcfg); + lastvalue = pwmcfg.period>>1; + pwmEnableChannelI(&PWMD1, 0, lastvalue); + + /* Start the timer interrupt */ + gptStart(&GPTD2, &gptcfg); + gptStartContinuous(&GPTD2, 0); +} + +static void gaudio_play_pwm_stop(void) { + /* Stop the timer interrupt */ + gptStopTimer(&GPTD2); + + /* Stop the PWM */ + pwmStop(&PWMD1); +} + +static void gaudio_play_pwm_setI(uint16_t value) { + if (value != lastvalue) { + lastvalue = value; + pwmEnableChannelI(&PWMD1, 0, value); + } +} + +#endif /* GAUDIO_PLAY_BOARD_H */ |