SPI.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. extern "C" {
  2. #include "stdint.h"
  3. #include "stdlib.h"
  4. #include "string.h"
  5. #include "stdio.h"
  6. #include "stdint.h"
  7. #include <unistd.h>
  8. #include "math.h"
  9. #include "ctype.h"
  10. #include <assert.h>
  11. }
  12. static void delay(unsigned int n)
  13. {
  14. usleep(1000 * n);
  15. }
  16. static void delayMicroseconds(unsigned int n)
  17. {
  18. usleep(n);
  19. }
  20. static unsigned long micros()
  21. {
  22. return 0;
  23. }
  24. static unsigned long millis()
  25. {
  26. return 0;
  27. }
  28. #define DEC 0
  29. #define HEX 1
  30. class _Serial {
  31. public:
  32. void begin(int speed) {
  33. }
  34. void write(int x) {
  35. printf("%c", x);
  36. }
  37. void print(const char c) {
  38. printf("%c", c);
  39. }
  40. void print(const char s[]) {
  41. printf("%s", s);
  42. }
  43. void print(int x, int base) {
  44. printf((base == DEC) ? "%d" : "%X", x);
  45. }
  46. void println(void) {
  47. printf("\n");
  48. }
  49. void println(const char c) {
  50. printf("%c\n", c);
  51. }
  52. void println(const char s[]) {
  53. printf("%s\n", s);
  54. }
  55. void println(int x, int base) {
  56. printf((base == DEC) ? "%d\n" : "%X\n", x);
  57. }
  58. };
  59. static _Serial Serial;
  60. #if 1
  61. extern "C" uint8_t spix(uint8_t);
  62. class _SPI {
  63. public:
  64. void begin() {
  65. }
  66. uint8_t transfer(uint8_t c) {
  67. assert(0);
  68. // uint8_t r = spix(c);
  69. return 0;
  70. }
  71. uint8_t transfer(uint8_t *m, size_t c) {
  72. assert(0);
  73. }
  74. };
  75. static _SPI SPI;
  76. #endif
  77. #define A0 0xa0
  78. #define A1 0xa1
  79. #define A2 0xa2
  80. #define OUTPUT 1
  81. #define INPUT 0
  82. #define HIGH 1
  83. #define LOW 0
  84. #define min(a, b) (((a) < (b)) ? (a) : (b))
  85. #define max(a, b) (((a) > (b)) ? (a) : (b))
  86. #define abs(x) (((x) < 0) ? (-(x)) : (x))
  87. static void pinMode(int, int)
  88. {
  89. }
  90. static int analogRead(int x)
  91. {
  92. return 0;
  93. }
  94. static int digitalRead(int x)
  95. {
  96. return 0;
  97. }
  98. static void digitalWrite(int pin, int state)
  99. {
  100. }
  101. static uint32_t seed = 7;
  102. static void randomSeed(unsigned int n)
  103. {
  104. seed = n | (n == 0);
  105. }
  106. static unsigned int xrandom()
  107. {
  108. seed ^= seed << 13;
  109. seed ^= seed >> 17;
  110. seed ^= seed << 5;
  111. return seed;
  112. }
  113. static unsigned int random(unsigned int n)
  114. {
  115. return xrandom() % n;
  116. }
  117. static unsigned int random(unsigned int a, unsigned int b)
  118. {
  119. return a + random(b - a);
  120. }
  121. typedef unsigned char byte;
  122. typedef const unsigned char prog_uchar;
  123. typedef const signed char prog_char;
  124. typedef const unsigned short prog_uint16_t;
  125. typedef const signed short prog_int16_t;
  126. typedef const unsigned long prog_uint32_t;
  127. #define pgm_read_byte(x) (*(prog_uchar*)(x))
  128. #define pgm_read_byte_near(x) pgm_read_byte(x)
  129. #define pgm_read_word(x) (*(prog_uint16_t*)(x))
  130. #define pgm_read_word_near(x) pgm_read_word(x)
  131. #define pgm_read_dword(x) (*(prog_uint32_t*)(x))
  132. #define pgm_read_dword_near(x) pgm_read_dword(x)
  133. #define PROGMEM
  134. #define memcpy_P(a,b,c) memcpy((a), (b), (c))
  135. #define strcpy_P(a,b) strcpy((a), (b))
  136. #define strlen_P(a) strlen((const char *)(a))
  137. #define highByte(x) ((x) >> 8)
  138. #define lowByte(x) ((x) & 255)
  139. #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
  140. long map(long x, long in_min, long in_max, long out_min, long out_max);