Simple single-color 8x8x8 LED Cube with AVRs
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

eq.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * eq.c
  3. *
  4. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  5. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  6. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  7. *
  8. * This file is part of LED-Cube.
  9. *
  10. * LED-Cube is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * LED-Cube is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #include <avr/io.h>
  24. #include <stdint.h>
  25. #include <util/delay.h>
  26. #include "eq.h"
  27. #include "adc.h"
  28. #define Trs 72
  29. #define Ts 19
  30. #define To 36
  31. uint8_t result[7] = {128, 128, 128, 128, 128, 128, 128};
  32. #define RESETPORT PORTC
  33. #define STROBEPORT PORTC
  34. #define RESET PC3
  35. #define STROBE PC2
  36. #define RESETON RESETPORT |= (1 << RESET)
  37. #define RESETOFF RESETPORT &= ~(1 << RESET)
  38. #define STROBEON STROBEPORT |= (1 << STROBE)
  39. #define STROBEOFF STROBEPORT &= ~(1 << STROBE)
  40. void equalizerInit(void);
  41. uint8_t *equalizerGet(void);
  42. void calcMultiplicator(uint8_t *d);
  43. void heightenTreble(uint8_t *d);
  44. void filterNoise(uint8_t *data);
  45. uint8_t getOffset(void);
  46. void equalizerInit(void) {
  47. RESETON;
  48. STROBEOFF;
  49. }
  50. uint8_t *equalizerGet(void) {
  51. uint8_t i;
  52. RESETOFF;
  53. _delay_us(Trs);
  54. for (i = 0; i < 7; i++) {
  55. STROBEON;
  56. _delay_us(Ts);
  57. STROBEOFF;
  58. _delay_us(To); // Wait for result
  59. adcStartConversion(0);
  60. result[i] = adcGetByte();
  61. }
  62. RESETON;
  63. asm volatile ("nop"); // Ensure minimal reset pulse width
  64. asm volatile ("nop"); // 2 NOPs at 16MHz are enough...
  65. filterNoise(result); // Filter lower values
  66. heightenTreble(result); // Heighten higher frequencies, cause they seem damped
  67. calcMultiplicator(result); // Multiply with Poti Position
  68. filterNoise(result); // Filter lower values
  69. return result;
  70. }
  71. void calcMultiplicator(uint8_t *d) {
  72. uint8_t i;
  73. uint16_t multiplicator = ((uint16_t)getOffset() + 100) / 10;
  74. for (i = 0; i < 7; i++) {
  75. d[i] = (d[i] * multiplicator) / 10;
  76. }
  77. }
  78. void heightenTreble(uint8_t *d) {
  79. d[6] = d[5] * 10 / 15; // Get practically nothing on this channel. So fake something...
  80. }
  81. void filterNoise(uint8_t *data) {
  82. uint8_t i;
  83. for (i = 0; i < 7; i++) {
  84. if (data[i] < 60) {
  85. data[i] = data[i] * 10 / 15; // / 1.5
  86. }
  87. }
  88. }
  89. uint8_t getOffset(void) {
  90. adcStartConversion(0x01);
  91. return adcGetByte();
  92. }