1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
-
- #include <avr/io.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <util/delay.h>
-
- #include "eq.h"
- #include "adc.h"
-
- #define RESETDELAY 1
- #define RESETSTROBEDELAY 72
- #define STROBEDELAY 18
- #define READDELAY 36
-
- #if ((STROBEDELAY * 2) + READDELAY) < 72
- #error Strobe to Strobe Delay too short
- #endif
-
- void equalizerInit(void) {
- DDRC |= 12;
-
-
- PORTC |= (1 << PC3);
- _delay_us(RESETDELAY);
-
- }
-
- void eqLed(uint8_t *d) {
- uint8_t pins[7] = { PD2, PD3, PD4, PD5, PD6, PD7, PB0 };
- uint8_t i;
-
- for (i = 0; i < 7; i++) {
- if (d[i] >= 127) {
- if (i < 6)
- PORTD |= (1 << pins[i]);
- else
- PORTB |= (1 << pins[i]);
- } else {
- if (i < 6)
- PORTD &= ~(1 << pins[i]);
- else
- PORTB &= ~(1 << pins[i]);
- }
- }
- }
-
- uint8_t *equalizerGet(void) {
- uint8_t *result = (uint8_t *)malloc(7);
- uint8_t i, offset = getOffset();
-
- PORTC &= ~(1 << PC3);
- _delay_us(RESETSTROBEDELAY);
-
- for (i = 0; i < 7; i++) {
- PORTC |= (1 << PC2);
- _delay_us(STROBEDELAY);
- PORTC &= ~(1 << PC2);
- adcStartConversion(0x00);
- _delay_us(READDELAY);
- result[i] = offset + adcGetByte();
- _delay_us(STROBEDELAY);
- }
-
- eqLed(result);
- return result;
- }
-
- uint8_t getOffset(void) {
- adcStartConversion(0x01);
- return (adcGetByte() / 2);
- }
|