twi.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. twi.h - TWI/I2C library for Wiring & Arduino
  3. Copyright (c) 2006 Nicholas Zambetti. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. #ifndef twi_h
  17. #define twi_h
  18. #include <inttypes.h>
  19. //#define ATMEGA8
  20. #ifndef TWI_FREQ
  21. #define TWI_FREQ 400000L
  22. #endif
  23. #ifndef TWI_BUFFER_LENGTH
  24. #define TWI_BUFFER_LENGTH 32
  25. #endif
  26. #define TWI_READY 0
  27. #define TWI_MRX 1
  28. #define TWI_MTX 2
  29. #define TWI_SRX 3
  30. #define TWI_STX 4
  31. void twi_init(void);
  32. void twi_disable(void);
  33. void twi_setAddress(uint8_t);
  34. void twi_setFrequency(uint32_t);
  35. uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t);
  36. uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t);
  37. uint8_t twi_transmit(const uint8_t*, uint8_t);
  38. void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) );
  39. void twi_attachSlaveTxEvent( void (*)(void) );
  40. void twi_reply(uint8_t);
  41. void twi_stop(void);
  42. void twi_releaseBus(void);
  43. #endif