From bedf92888276b38ed9332595e4a58943bf83f7ca Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 9 Sep 2015 22:10:01 +0200 Subject: [PATCH] Move all base apps to a base subdirectory in apps. This prepares for merge of modules branches, which will instead have their own subdirectory, preventing the hasle of cherry-picking common code to each and every branch. Warning : Makefile modifications according to these moves will be in the next commit ! --- microphone/Makefile | 10 ++++ microphone/README | 32 +++++++++++ microphone/main.c | 129 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 microphone/Makefile create mode 100644 microphone/README create mode 100644 microphone/main.c diff --git a/microphone/Makefile b/microphone/Makefile new file mode 100644 index 0000000..91407f3 --- /dev/null +++ b/microphone/Makefile @@ -0,0 +1,10 @@ +# Makefile for GPIO Demo Module apps + +NAME = $(shell basename $(CURDIR)) + +.PHONY: $(NAME).bin +$(NAME).bin: + @make -C ../.. --no-print-directory NAME=$(NAME) apps/$(NAME)/$@ + +clean mrproper: + @make -C ../.. --no-print-directory $@ diff --git a/microphone/README b/microphone/README new file mode 100644 index 0000000..5a03a20 --- /dev/null +++ b/microphone/README @@ -0,0 +1,32 @@ +ADC and electret/mems microphone example + +Copyright 2015 Nathael Pajani + + +/* **************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +This example shows the support of the internal ADC in continuous sampling (burst) +mode, with high data rate transmission over serial line (1.152Mbits/s) + +The conversion results are sent over the UART0 serial line (1152000 8n1) creating +simple raw, 8bit, 1channel audio files. +Play them using aplay and the following parameters : +$ aplay -t raw -f U8 -r 22000 aud.raw + +The quality is much better using mems microphone. Used ADMP401 for the test, on +a Sparkfun breakout board. + diff --git a/microphone/main.c b/microphone/main.c new file mode 100644 index 0000000..e4726a9 --- /dev/null +++ b/microphone/main.c @@ -0,0 +1,129 @@ +/**************************************************************************** + * apps/microphone/main.c + * + * ADC example with very high sample rate and auto Tx on serial at high speed. + * + * Copyright 2013-2014 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +#include +#include "core/lpc_regs_12xx.h" +#include "core/lpc_core_cm0.h" +#include "core/pio.h" +#include "core/system.h" +#include "core/systick.h" +#include "lib/stdio.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" +#include "extdrv/status_led.h" +#include "drivers/adc.h" + + +#define MODULE_VERSION 0x04 +#define MODULE_NAME "GPIO Demo Module" + + +#define SELECTED_FREQ FREQ_SEL_48MHz + +/***************************************************************************** */ +/* Pins configuration */ +/* pins blocks are passed to set_pins() for pins configuration. + * Unused pin blocks can be removed safely with the corresponding set_pins() call + * All pins blocks may be safelly merged in a single block for single set_pins() call.. + */ +const struct pio_config common_pins[] = { + /* UART 0 */ + { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL }, + { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL }, + ARRAY_LAST_PIO, +}; + +const struct pio_config adc_pins[] = { + { LPC_ADC_AD0_PIO_0_30, LPC_IO_ANALOG }, + { LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG }, + { LPC_ADC_AD2_PIO_1_0, LPC_IO_ANALOG }, + { LPC_ADC_AD3_PIO_1_1, LPC_IO_ANALOG }, + { LPC_ADC_AD4_PIO_1_2, LPC_IO_ANALOG }, + { LPC_ADC_AD5_PIO_1_3, LPC_IO_ANALOG }, + ARRAY_LAST_PIO, +}; + +const struct pio status_led_green = LPC_GPIO_1_4; +const struct pio status_led_red = LPC_GPIO_1_5; + + + +/***************************************************************************** */ +void system_init() +{ + /* Stop the watchdog */ + stop_watchdog(); /* Do it right now, before it gets a chance to break in */ + + /* Note: Brown-Out detection must be powered to operate the ADC. adc_on() will power + * it back on if called after system_init() */ + system_brown_out_detection_config(0); + system_set_default_power_state(); + clock_config(SELECTED_FREQ); + set_pins(common_pins); + set_pins(adc_pins); + gpio_on(); + status_led_config(&status_led_green, &status_led_red); + /* System tick timer MUST be configured and running in order to use the sleeping + * functions */ + systick_timer_on(1); /* 1ms */ + systick_start(); +} + +/* Define our fault handler. This one is not mandatory, the dummy fault handler + * will be used when it's not overridden here. + * Note : The default one does a simple infinite loop. If the watchdog is deactivated + * the system will hang. + */ +void fault_info(const char* name, uint32_t len) +{ + serial_write(0, name, len); + /* Wait for end of Tx */ + serial_flush(0); + /* FIXME : Perform soft reset of the micro-controller ! */ + while (1); +} + + + +/***************************************************************************** */ +int main(void) { + system_init(); + uart_on(0, 1152000, NULL); + adc_on(); + + adc_start_burst_conversion(LPC_ADC_CHANNEL(0)); + while (1) { + /* ADC Test */ + uint16_t val = 0; + uint8_t tmp = 0; + adc_get_value(&val, LPC_ADC_NUM(0)); + tmp = (val >> 2); + serial_write(0, (char*)&tmp, 1); + usleep(20); + } + return 0; +} + + + -- 2.43.0