Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

twi.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef _I2CMASTER_H
  2. #define _I2CMASTER_H 1
  3. /*************************************************************************
  4. * Title: C include file for the I2C master interface
  5. * (i2cmaster.S or twimaster.c)
  6. * Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
  7. * File: $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $
  8. * Software: AVR-GCC 3.4.3 / avr-libc 1.2.3
  9. * Target: any AVR device
  10. * Usage: see Doxygen manual
  11. **************************************************************************/
  12. #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
  13. #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
  14. #endif
  15. #include <avr/io.h>
  16. /** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */
  17. #define I2C_READ 1
  18. /** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */
  19. #define I2C_WRITE 0
  20. /**
  21. @brief initialize the I2C master interace. Need to be called only once
  22. @param void
  23. @return none
  24. */
  25. extern void i2c_init(void);
  26. /**
  27. @brief Terminates the data transfer and releases the I2C bus
  28. @param void
  29. @return none
  30. */
  31. extern void i2c_stop(void);
  32. /**
  33. @brief Issues a start condition and sends address and transfer direction
  34. @param addr address and transfer direction of I2C device
  35. @retval 0 device accessible
  36. @retval 1 failed to access device
  37. */
  38. extern unsigned char i2c_start(unsigned char addr);
  39. /**
  40. @brief Issues a repeated start condition and sends address and transfer direction
  41. @param addr address and transfer direction of I2C device
  42. @retval 0 device accessible
  43. @retval 1 failed to access device
  44. */
  45. extern unsigned char i2c_rep_start(unsigned char addr);
  46. /**
  47. @brief Issues a start condition and sends address and transfer direction
  48. If device is busy, use ack polling to wait until device ready
  49. @param addr address and transfer direction of I2C device
  50. @return none
  51. */
  52. extern void i2c_start_wait(unsigned char addr);
  53. /**
  54. @brief Send one byte to I2C device
  55. @param data byte to be transfered
  56. @retval 0 write successful
  57. @retval 1 write failed
  58. */
  59. extern unsigned char i2c_write(unsigned char data);
  60. /**
  61. @brief read one byte from the I2C device, request more data from device
  62. @return byte read from I2C device
  63. */
  64. extern unsigned char i2c_readAck(void);
  65. /**
  66. @brief read one byte from the I2C device, read is followed by a stop condition
  67. @return byte read from I2C device
  68. */
  69. extern unsigned char i2c_readNak(void);
  70. /**
  71. @brief read one byte from the I2C device
  72. Implemented as a macro, which calls either i2c_readAck or i2c_readNak
  73. @param ack 1 send ack, request more data from device<br>
  74. 0 send nak, read is followed by a stop condition
  75. @return byte read from I2C device
  76. */
  77. extern unsigned char i2c_read(unsigned char ack);
  78. #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
  79. #endif