twi.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 100000L
  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_setAddress(uint8_t);
  33. uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t);
  34. uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t);
  35. uint8_t twi_transmit(const uint8_t*, uint8_t);
  36. void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) );
  37. void twi_attachSlaveTxEvent( void (*)(void) );
  38. void twi_reply(uint8_t);
  39. void twi_stop(void);
  40. void twi_releaseBus(void);
  41. #endif