keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

PortWrite_PCA9655E.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "PortWrite_PCA9655E.h"
  2. /* begin() is called from Scanner_IOE::begin().
  3. Initiates I2C bus and configures port pins to output.
  4. PCA9655E supports I2C SCL Clock Frequencies: 100 kHz, 400 kHz, 1000 kHz (Datasheet page 1 & 6)
  5. The electrical limitation to bus speed is bus capacitance and the length of the wires involved.
  6. Longer wires require lower clock speeds.
  7. http://playground.arduino.cc/Main/WireLibraryDetailedReference > Wire.setclock()
  8. */
  9. void PortWrite_PCA9655E::begin()
  10. {
  11. Wire.begin(); //initiate I2C bus to 100 kHz
  12. //Wire.setClock(400000L); //set I2C bus to 400 kHz (have not tested 400 kHz)
  13. Wire.beginTransmission(port.DEVICE_ADDR);
  14. Wire.write(port.num + 6); //configuration byte command
  15. Wire.write(0); //configure all pins as output
  16. Wire.endTransmission();
  17. }
  18. /* write() sets pin output to logicLevel.
  19. pin is bit pattern, where pin being strobed is 1.
  20. logicLevel is HIGH or LOW.
  21. write() does not overwrite the other pins.
  22. */
  23. void PortWrite_PCA9655E::write(const uint8_t pin, const bool logicLevel)
  24. {
  25. if (logicLevel == LOW) //if pin low
  26. {
  27. port.outputVal &= ~pin; //set pin output to low
  28. }
  29. else //if strobestrobe high
  30. {
  31. port.outputVal |= pin; //set pin output to high
  32. }
  33. Wire.beginTransmission(port.DEVICE_ADDR);
  34. Wire.write(port.num + 2); //output Byte command
  35. Wire.write(port.outputVal);
  36. Wire.endTransmission();
  37. }