wii_i2c.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef WII_I2C_H_
  2. #define WII_I2C_H_
  3. #include <stdint.h>
  4. //#include "wii_ec.h"
  5. //----------------------------------------------------------------------------- ----------------------------------------
  6. // i2c bus details
  7. //
  8. // https://www.best-microcontroller-projects.com/i2c-tutorial.html
  9. // https://web.archive.org/web/20220000000000*/https://www.best-microcontroller-projects.com/i2c-tutorial.html
  10. // https://training.ti.com/introduction-i2c-reserved-addresses
  11. //
  12. // After the (special) START "bit"...
  13. // the first 8bits (byte) of i2c data are the 7bit i2c Address,
  14. // FOLLOWED by 1bit to signify a READ or WRITE {0=write, 1=read}
  15. // The data is transmitted BIG-Endian, IE. MSb first [human readable]
  16. // So the address actually lives in the TOP (MSb's) of the first "byte", (with bit0 being used as the read/write flag)
  17. //
  18. // The read() and write() functions on the FZ will set the LSb appropriately,
  19. // BUT they do NOT shift the address left to make room for it!
  20. // So the address you give to read/write() MUST be given as (7bitAddress << 1)
  21. //
  22. // When we read: After we send the read command, we wait for i2cReadWait uS before reading the data
  23. //
  24. // targets/f7/furi_hal/furi_hal_i2c_types.h
  25. #define i2cBus (&furi_hal_i2c_handle_external) // FZ external i2c bus
  26. #define i2cAddr (ec_i2cAddr << 1)
  27. #define i2cTimeout (3) // in mS
  28. #define i2cReadWait (300) //! 300uS: how low can we take this?
  29. //----------------------------------------------------------------------------- ----------------------------------------
  30. // public functions
  31. //
  32. typedef struct wiiEC wiiEC_t;
  33. bool ecInit(wiiEC_t* const pec, const uint8_t* encKey);
  34. int ecRead(wiiEC_t* const pec);
  35. #endif //WII_I2C_H_