Mirf.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de>
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use, copy,
  7. modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be
  11. included in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  16. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  17. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. DEALINGS IN THE SOFTWARE.
  20. $Id$
  21. */
  22. #ifndef _MIRF_H_
  23. #define _MIRF_H_
  24. #include <Arduino.h>
  25. #include "nRF24L01.h"
  26. #include "MirfSpiDriver.h"
  27. // Nrf24l settings
  28. #define mirf_ADDR_LEN 5
  29. #define mirf_CONFIG ((1<<EN_CRC) | (0<<CRCO) )
  30. class Nrf24l {
  31. public:
  32. Nrf24l();
  33. void init();
  34. void config();
  35. void send(uint8_t *value);
  36. void setRADDR(uint8_t * adr);
  37. void setTADDR(uint8_t * adr);
  38. bool dataReady();
  39. bool isSending();
  40. bool rxFifoEmpty();
  41. bool txFifoEmpty();
  42. void getData(uint8_t * data);
  43. uint8_t getStatus();
  44. void transmitSync(uint8_t *dataout,uint8_t len);
  45. void transferSync(uint8_t *dataout,uint8_t *datain,uint8_t len);
  46. void configRegister(uint8_t reg, uint8_t value);
  47. void readRegister(uint8_t reg, uint8_t * value, uint8_t len);
  48. void writeRegister(uint8_t reg, uint8_t * value, uint8_t len);
  49. void powerUpRx();
  50. void powerUpTx();
  51. void powerDown();
  52. void csnHi();
  53. void csnLow();
  54. void ceHi();
  55. void ceLow();
  56. void flushRx();
  57. /*
  58. * In sending mode.
  59. */
  60. uint8_t PTX;
  61. /*
  62. * CE Pin controls RX / TX, default 8.
  63. */
  64. uint8_t cePin;
  65. /*
  66. * CSN Pin Chip Select Not, default 7.
  67. */
  68. uint8_t csnPin;
  69. /*
  70. * Channel 0 - 127 or 0 - 84 in the US.
  71. */
  72. uint8_t channel;
  73. /*
  74. * Payload width in bytes default 16 max 32.
  75. */
  76. uint8_t payload;
  77. /*
  78. * Spi interface (must extend spi).
  79. */
  80. MirfSpiDriver *spi;
  81. };
  82. extern Nrf24l Mirf;
  83. #endif /* _MIRF_H_ */