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

PortPCA9655E.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "PortPCA9655E.h"
  2. /* begin() is called from Scanner_IOE::begin(). Initiates I2C bus.
  3. PCA9655E supports I2C SCL Clock Frequencies: 100 kHz, 400 kHz, 1000 kHz (Datasheet page 1 & 6)
  4. The electrical limitation to bus speed is bus capacitance and the length of the wires involved.
  5. Longer wires require lower clock speeds.
  6. http://playground.arduino.cc/Main/WireLibraryDetailedReference > Wire.setclock()
  7. */
  8. void PortPCA9655E::beginProtocol()
  9. {
  10. Wire.begin(); //initiate I2C bus to 100 kHz
  11. //Wire.setClock(400000L); //set I2C bus to 400 kHz (have not tested 400 kHz)
  12. }
  13. /* begin() is called from Scanner_IOE::begin().
  14. Configures read pins to input.
  15. strobeOn is not used because PCA9655E has no pull-up resistors.
  16. */
  17. void PortPCA9655E::begin(const uint8_t strobeOn)
  18. {
  19. Wire.beginTransmission(deviceAddr);
  20. Wire.write(portNum + 6); //configuration byte command
  21. Wire.write(readPins); //0=output (for strobe and LED), 1=input (for read)
  22. Wire.endTransmission();
  23. }
  24. /* write() sets pin output to logicLevel.
  25. pin is bit pattern, where pin being strobed is 1.
  26. logicLevel is HIGH or LOW.
  27. write() does not overwrite the other pins.
  28. */
  29. void PortPCA9655E::write(const uint8_t pin, const bool logicLevel)
  30. {
  31. if (logicLevel == LOW)
  32. {
  33. outputVal &= ~pin; //set pin output to low
  34. }
  35. else
  36. {
  37. outputVal |= pin; //set pin output to high
  38. }
  39. Wire.beginTransmission(deviceAddr);
  40. Wire.write(portNum + 2); //output Byte command
  41. Wire.write(outputVal);
  42. Wire.endTransmission();
  43. }
  44. /* read() returns portState.
  45. Only portState bits of readPins are valid.
  46. */
  47. uint8_t PortPCA9655E::read()
  48. {
  49. Wire.beginTransmission(deviceAddr);
  50. Wire.write(portNum); //input byte command
  51. Wire.endTransmission(false); //PCA9655E needs false to send a restart
  52. Wire.requestFrom(deviceAddr, 1u); //request one byte from input port
  53. return Wire.read();
  54. }