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.2KB

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