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 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // Free after usage!
  30. uint8_t *getFrame(uint16_t frameNumber) {
  31. return memGetBytes(32 + (65 * frameNumber), 65);
  32. }
  33. // 65 bytes framedata, data and duration...
  34. void setFrame(uint16_t frameNumber, uint8_t *frameData) {
  35. memWriteBytes(32 + (65 * frameNumber), frameData, 65);
  36. }
  37. void clearMem() {
  38. uint32_t i;
  39. for (i = 0; i < MemLength; i++) {
  40. memWriteByte(i, 0);
  41. }
  42. }
  43. uint16_t getAnimationCount() {
  44. uint8_t lsb = memGetByte(0);
  45. uint8_t msb = memGetByte(1);
  46. uint16_t animationCount = (uint16_t)lsb;
  47. return (animationCount | (((uint16_t)(msb)) << 8));
  48. }
  49. void setAnimationCount(uint16_t c) {
  50. uint8_t lsb = (uint8_t)(c & 0x00FF);
  51. uint8_t msb = (uint8_t)((c & 0xFF00) >> 8);
  52. memWriteByte(0, lsb);
  53. memWriteByte(1, msb);
  54. }
  55. void setGeneralPurposeByte(uint8_t address, uint8_t data) {
  56. if (address < 30) {
  57. memWriteByte(address + 2, data);
  58. }
  59. }
  60. uint8_t getGeneralPurposeByte(uint8_t address) {
  61. if (address < 30) {
  62. return memGetByte(address + 2);
  63. } else {
  64. return 0;
  65. }
  66. }