luat_i2c_air105.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "luat_base.h"
  2. #include "luat_i2c.h"
  3. #include "app_interface.h"
  4. #define LUAT_LOG_TAG "luat.i2c"
  5. #include "luat_log.h"
  6. int luat_i2c_exist(int id) {
  7. return id == 0;
  8. }
  9. int luat_i2c_setup(int id, int speed, int slaveaddr) {
  10. if (speed == 0)
  11. speed = 100 * 1000; // SLOW
  12. else if (speed == 1)
  13. speed = 400 * 1000; // FAST
  14. else if (speed == 2)
  15. speed = 400 * 1000; // SuperFast
  16. GPIO_Iomux(GPIOE_06, 2);
  17. GPIO_Iomux(GPIOE_07, 2);
  18. I2C_MasterSetup(id, speed);
  19. return 0;
  20. }
  21. int luat_i2c_close(int id) {
  22. return 0;
  23. }
  24. int luat_i2c_send(int id, int addr, void* buff, size_t len) {
  25. I2C_BlockWrite(id, addr, (const uint8_t *)buff, len, 100, NULL, NULL);
  26. // I2C_Prepare(id, addr, 1, NULL, NULL);
  27. // I2C_MasterXfer(id, I2C_OP_WRITE, 0, buff, len, 20);
  28. return 0;
  29. }
  30. int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
  31. I2C_BlockRead(id, addr, 0, (uint8_t *)buff, len, 100, NULL, NULL);
  32. // I2C_Prepare(id, addr, 1, NULL, NULL);
  33. // I2C_MasterXfer(id, I2C_OP_READ, 0, buff, len, 20);
  34. return 0;
  35. }