Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

memLayer.c 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * memLayer.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 <stdint.h>
  24. #include <avr/io.h>
  25. #include <stdlib.h>
  26. #include <avr/wdt.h>
  27. #include "mem.h"
  28. #include "memLayer.h"
  29. #include "serial.h"
  30. // We have 128*1024 bytes
  31. // A Frame needs 65 bytes (64 data + duration)
  32. // We place 2016 Frames in mem => 131040
  33. // That gives us 32 bytes at the beginning, 0 -> 31
  34. // The first frame starts at 32
  35. // Framecount in 0 and 1
  36. // General Purpose bytes 0 to 29, starting at 2
  37. // Free after usage!
  38. uint8_t *getFrame(uint16_t frameNumber) {
  39. return memGetBytes(32 + (65 * frameNumber), 65);
  40. }
  41. // 65 bytes framedata, data and duration...
  42. void setFrame(uint16_t frameNumber, uint8_t *frameData) {
  43. memWriteBytes(32 + (65 * frameNumber), frameData, 65);
  44. }
  45. void setDuration(uint16_t frameNumber, uint8_t duration) {
  46. memWriteByte(32 + 64 + (65 * frameNumber), duration);
  47. }
  48. void clearMem() {
  49. uint32_t i;
  50. for (i = 0; i < MemLength; i++) {
  51. memWriteByte(i, 0);
  52. wdt_reset();
  53. }
  54. }
  55. uint16_t getAnimationCount() {
  56. uint8_t lsb = memGetByte(0);
  57. uint8_t msb = memGetByte(1);
  58. uint16_t animationCount = (uint16_t)lsb;
  59. animationCount |= (((uint16_t)(msb)) << 8);
  60. if (animationCount <= 2016) {
  61. return animationCount;
  62. } else {
  63. return 2016;
  64. }
  65. }
  66. void setAnimationCount(uint16_t c) {
  67. uint8_t lsb = (uint8_t)(c & 0x00FF);
  68. uint8_t msb = (uint8_t)((c & 0xFF00) >> 8);
  69. memWriteByte(0, lsb);
  70. memWriteByte(1, msb);
  71. }
  72. void setGeneralPurposeByte(uint8_t address, uint8_t data) {
  73. if (address < 30) {
  74. memWriteByte(address + 2, data);
  75. }
  76. }
  77. uint8_t getGeneralPurposeByte(uint8_t address) {
  78. if (address < 30) {
  79. return memGetByte(address + 2);
  80. } else {
  81. return 0;
  82. }
  83. }