You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

  1. #pragma once
  2. #include <util/delay.h>
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "quantum.h"
  6. #include "i2c_master.h"
  7. #include "matrix.h"
  8. extern i2c_status_t mcp23018_status;
  9. #define ERGODOX_EZ_I2C_TIMEOUT 1000
  10. #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
  11. #define CPU_16MHz 0x00
  12. // I2C aliases and register addresses (see "mcp23018.md")
  13. //#define I2C_ADDR 0b0100000
  14. #define I2C_ADDR 0x20
  15. #define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE )
  16. #define I2C_ADDR_READ ( (I2C_ADDR<<1) | I2C_READ )
  17. #define IODIRA 0x00 // i/o direction register
  18. #define IODIRB 0x01
  19. #define GPPUA 0x0C // GPIO pull-up resistor register
  20. #define GPPUB 0x0D
  21. #define GPIOA 0x12 // general purpose i/o port register (write modifies OLAT)
  22. #define GPIOB 0x13
  23. #define OLATA 0x14 // output latch register
  24. #define OLATB 0x15
  25. void init_ergodox(void);
  26. uint8_t init_mcp23018(void);
  27. /* ---------- LEFT HAND ----------- ---------- RIGHT HAND ---------- */
  28. #define LAYOUT( \
  29. L00,L01,L02,L03,L04,L05, R00,R01,R02,R03,R04,R05) \
  30. \
  31. /* matrix positions */ \
  32. { \
  33. {R00}, \
  34. {R01}, \
  35. {R02}, \
  36. {R03}, \
  37. {R04}, \
  38. {R05}, \
  39. {L05}, \
  40. {L04}, \
  41. {L03}, \
  42. {L02}, \
  43. {L01}, \
  44. {L00}, \
  45. }