Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

memLayer.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * memLayer.c
  3. *
  4. * Copyright 2012 Thomas Buck <xythobuz@me.com>
  5. *
  6. * This file is part of LED-Cube.
  7. *
  8. * LED-Cube is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * LED-Cube is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <stdint.h>
  22. #include <avr/io.h>
  23. #include <stdlib.h>
  24. #include <avr/wdt.h>
  25. #include "mem.h"
  26. #include "memLayer.h"
  27. #include "serial.h"
  28. // We have 128*1024 bytes
  29. // A Frame needs 65 bytes (64 data + duration)
  30. // We place 2016 Frames in mem => 131040
  31. // That gives us 32 bytes at the beginning, 0 -> 31
  32. // The first frame starts at 32
  33. // Framecount in 0 and 1
  34. // General Purpose bytes 0 to 29, starting at 2
  35. // Free after usage!
  36. uint8_t *getFrame(uint16_t frameNumber) {
  37. return memGetBytes(32 + (65 * frameNumber), 65);
  38. }
  39. // 65 bytes framedata, data and duration...
  40. void setFrame(uint16_t frameNumber, uint8_t *frameData) {
  41. memWriteBytes(32 + (65 * frameNumber), frameData, 65);
  42. }
  43. void setDuration(uint16_t frameNumber, uint8_t duration) {
  44. memWriteByte(32 + 64 + (65 * frameNumber), duration);
  45. }
  46. void clearMem() {
  47. uint32_t i;
  48. for (i = 0; i < MemLength; i++) {
  49. memWriteByte(i, 0);
  50. wdt_reset();
  51. }
  52. }
  53. uint16_t getAnimationCount() {
  54. uint8_t lsb = memGetByte(0);
  55. uint8_t msb = memGetByte(1);
  56. uint16_t animationCount = (uint16_t)lsb;
  57. animationCount |= (((uint16_t)(msb)) << 8);
  58. if (animationCount <= 2016) {
  59. return animationCount;
  60. } else {
  61. return 2016;
  62. }
  63. }
  64. void setAnimationCount(uint16_t c) {
  65. uint8_t lsb = (uint8_t)(c & 0x00FF);
  66. uint8_t msb = (uint8_t)((c & 0xFF00) >> 8);
  67. memWriteByte(0, lsb);
  68. memWriteByte(1, msb);
  69. }
  70. void setGeneralPurposeByte(uint8_t address, uint8_t data) {
  71. if (address < 30) {
  72. memWriteByte(address + 2, data);
  73. }
  74. }
  75. uint8_t getGeneralPurposeByte(uint8_t address) {
  76. if (address < 30) {
  77. return memGetByte(address + 2);
  78. } else {
  79. return 0;
  80. }
  81. }