keybrd library is an open source library for creating custom-keyboard firmware.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.

Port_PCA9655E.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "Port_PCA9655E.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 Port_PCA9655E::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 Port_PCA9655E::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 Port_PCA9655E::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 Port_PCA9655E::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. }