34 #include "dev/sound-sensor.h"
38 #define MIC_MIN_SENS 150
41 const struct sensors_sensor sound_sensor;
43 static unsigned int sound, micdiff, micmax, avgmax;
45 static int8_t sample_div;
47 static int16_t *sample_buffer;
48 static int buffer_size;
55 micdiff = micdiff +
abs(ADC12MEM4 - sound) - (micdiff >> 3);
60 if(ctr >= sample_div) {
62 sample_buffer[buf_pos++] = sound;
63 if(buf_pos >= buffer_size) {
65 sensors_changed(&sound_sensor);
110 configure(
int type,
int value)
113 case SENSORS_HW_INIT:
120 if(!irq_adc12_active(4)) {
121 sound = micdiff = micmax = 0;
127 irq_adc12_activate(4, (INCH_0 + SREF_0), irq);
130 irq_adc12_deactivate(4);
142 return irq_adc12_active(4);
144 return (mode != SAMPLE) && irq_adc12_active(4);
150 sound_sensor_start_sample(
void)
152 if(buffer_size > 0) {
160 sound_sensor_set_buffer(int16_t *buffer,
int buf_size,
int divider)
162 sample_buffer = buffer;
163 buffer_size = buf_size;
164 sample_div = divider;
167 SENSORS_SENSOR(sound_sensor, SOUND_SENSOR,
168 value, configure, status);