Simple single-color 8x8x8 LED Cube with AVRs
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

memLayer.c 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // 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 clearMem() {
  44. uint32_t i;
  45. for (i = 0; i < MemLength; i++) {
  46. memWriteByte(i, 0);
  47. wdt_reset();
  48. }
  49. }
  50. uint16_t getAnimationCount() {
  51. uint8_t lsb = memGetByte(0);
  52. uint8_t msb = memGetByte(1);
  53. uint16_t animationCount = (uint16_t)lsb;
  54. animationCount |= (((uint16_t)(msb)) << 8);
  55. if (animationCount <= 2016) {
  56. return animationCount;
  57. } else {
  58. return 2016;
  59. }
  60. }
  61. void setAnimationCount(uint16_t c) {
  62. uint8_t lsb = (uint8_t)(c & 0x00FF);
  63. uint8_t msb = (uint8_t)((c & 0xFF00) >> 8);
  64. memWriteByte(0, lsb);
  65. memWriteByte(1, msb);
  66. }
  67. void setGeneralPurposeByte(uint8_t address, uint8_t data) {
  68. if (address < 30) {
  69. memWriteByte(address + 2, data);
  70. }
  71. }
  72. uint8_t getGeneralPurposeByte(uint8_t address) {
  73. if (address < 30) {
  74. return memGetByte(address + 2);
  75. } else {
  76. return 0;
  77. }
  78. }