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.

207 lines
6.0 KiB

Handwired/Dactyl keyboard (#2058) * Copy the ergodox_ez code to handwired/dactyl Differences from the Ergodox: * Use QMK_SUBPROJECT_H instead of QMK_KEYBOARD_H, since it's under handwired * Omitted several keymaps. They'll eventually be broken (since the Dactyl has fewer keys), and I don't want to try to fix them. * Omitted the keymap images for the default layout, since they depict a different keyboard. * Everything that said Ergodox now says Dactyl, naturally. * [whitespace] Delete trailing whitespace My editor does this automatically so it's just gonna keep cropping up... * Cut the dactyl down to the right number of columns (Remember, throughout matrix.c, everything called "row" is really a column, and vice-versa). * Remove LED-related code * Tighten up the Dactyl's build options * Whitespace cleanup in twimaster.c * Hardtabs -> spaces * No more trailing whitespace * Typo fix * Correct the CPU frequency units The Teensy's CPU definitely doesn't run at 16 petahertz... * Restore access to ONEHAND_ENABLE I turned it off in 26d47cb42622d990a7c3335e7fcc151aa3edfbf0 while desperately debugging; I just wanted to ensure it wasn't causing the problem I was seeing. It was not, in fact, causing the problem, so it's back. Also fixed the swap matrix in dactyl.c, since it still referred to columns that exist in the Ergodox but not the Dactyl. * Clearer phrasing about TWI's effect on scan rate * Fix up the Dactyl's firmware-loading instructions Sadly, the Dactyl has no hole for the onboard reset button. * Dvorak keymap for the Dactyl * The Erincalling Layout * Erincalling layout: Add a := key I've been working in Go, which uses := a lot, and it's awkward to type in this layout. * Dactyl README: link to the dactyl-keyboard repo * Add a missing copyright line I don't know how much this matters? Honestly, it's enough for me that my name is on the git commit. But hey, let's be consistent until there's a specific reason not to be, right? * Dactyl: remove commented-out code I hate it I hate it I hate it There's not even any information about what it was trying to do!!!! >:( * Add a note about the row/column ridiculousness * [whitespace] realign some constants * Don't claim B4 is tied to VCC It doesn't matter at all? I honestly don't know what the reason ever was. It looks like it dates back to the original ErgoDox and I've never seen one sentence about the purpose. I've been skipping that wire for some time, and I promise it works fine. * Dactyl keymaps: Send RALT for right-hand alt key Not terribly important but I just like things tidy OK * typo fix * Refer to "dactyl.h" explicitly QMK_SUBPROJECT_H has been working locally, but fails in CI. Strange! * Dactyl: Don't use QMK_SUBPROJECT_H at all It's still breaking in CI, even though it was a never a problem locally.
6 years ago
  1. /*************************************************************************
  2. * Title: I2C master library using hardware TWI interface
  3. * Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
  4. * File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $
  5. * Software: AVR-GCC 3.4.3 / avr-libc 1.2.3
  6. * Target: any AVR device with hardware TWI
  7. * Usage: API compatible with I2C Software Library i2cmaster.h
  8. **************************************************************************/
  9. #include <inttypes.h>
  10. #include <compat/twi.h>
  11. #include <i2cmaster.h>
  12. /* define CPU frequency in Hz here if not defined in Makefile */
  13. #ifndef F_CPU
  14. #define F_CPU 16000000UL
  15. #endif
  16. /* I2C clock in Hz */
  17. #define SCL_CLOCK 400000L
  18. /*************************************************************************
  19. Initialization of the I2C bus interface. Need to be called only once
  20. *************************************************************************/
  21. void i2c_init(void)
  22. {
  23. /* initialize TWI clock
  24. * minimal values in Bit Rate Register (TWBR) and minimal Prescaler
  25. * bits in the TWI Status Register should give us maximal possible
  26. * I2C bus speed - about 444 kHz
  27. *
  28. * for more details, see 20.5.2 in ATmega16/32 secification
  29. */
  30. TWSR = 0; /* no prescaler */
  31. TWBR = 10; /* must be >= 10 for stable operation */
  32. }/* i2c_init */
  33. /*************************************************************************
  34. Issues a start condition and sends address and transfer direction.
  35. return 0 = device accessible, 1= failed to access device
  36. *************************************************************************/
  37. unsigned char i2c_start(unsigned char address)
  38. {
  39. uint8_t twst;
  40. // send START condition
  41. TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
  42. // wait until transmission completed
  43. while(!(TWCR & (1<<TWINT)));
  44. // check value of TWI Status Register. Mask prescaler bits.
  45. twst = TW_STATUS & 0xF8;
  46. if ( (twst != TW_START) && (twst != TW_REP_START)) return 1;
  47. // send device address
  48. TWDR = address;
  49. TWCR = (1<<TWINT) | (1<<TWEN);
  50. // wail until transmission completed and ACK/NACK has been received
  51. while(!(TWCR & (1<<TWINT)));
  52. // check value of TWI Status Register. Mask prescaler bits.
  53. twst = TW_STATUS & 0xF8;
  54. if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return 1;
  55. return 0;
  56. }/* i2c_start */
  57. /*************************************************************************
  58. Issues a start condition and sends address and transfer direction.
  59. If device is busy, use ack polling to wait until device is ready
  60. Input: address and transfer direction of I2C device
  61. *************************************************************************/
  62. void i2c_start_wait(unsigned char address)
  63. {
  64. uint8_t twst;
  65. while ( 1 )
  66. {
  67. // send START condition
  68. TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
  69. // wait until transmission completed
  70. while(!(TWCR & (1<<TWINT)));
  71. // check value of TWI Status Register. Mask prescaler bits.
  72. twst = TW_STATUS & 0xF8;
  73. if ( (twst != TW_START) && (twst != TW_REP_START)) continue;
  74. // send device address
  75. TWDR = address;
  76. TWCR = (1<<TWINT) | (1<<TWEN);
  77. // wail until transmission completed
  78. while(!(TWCR & (1<<TWINT)));
  79. // check value of TWI Status Register. Mask prescaler bits.
  80. twst = TW_STATUS & 0xF8;
  81. if ( (twst == TW_MT_SLA_NACK )||(twst ==TW_MR_DATA_NACK) )
  82. {
  83. /* device busy, send stop condition to terminate write operation */
  84. TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
  85. // wait until stop condition is executed and bus released
  86. while(TWCR & (1<<TWSTO));
  87. continue;
  88. }
  89. //if( twst != TW_MT_SLA_ACK) return 1;
  90. break;
  91. }
  92. }/* i2c_start_wait */
  93. /*************************************************************************
  94. Issues a repeated start condition and sends address and transfer direction
  95. Input: address and transfer direction of I2C device
  96. Return: 0 device accessible
  97. 1 failed to access device
  98. *************************************************************************/
  99. unsigned char i2c_rep_start(unsigned char address)
  100. {
  101. return i2c_start( address );
  102. }/* i2c_rep_start */
  103. /*************************************************************************
  104. Terminates the data transfer and releases the I2C bus
  105. *************************************************************************/
  106. void i2c_stop(void)
  107. {
  108. /* send stop condition */
  109. TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
  110. // wait until stop condition is executed and bus released
  111. while(TWCR & (1<<TWSTO));
  112. }/* i2c_stop */
  113. /*************************************************************************
  114. Send one byte to I2C device
  115. Input: byte to be transfered
  116. Return: 0 write successful
  117. 1 write failed
  118. *************************************************************************/
  119. unsigned char i2c_write( unsigned char data )
  120. {
  121. uint8_t twst;
  122. // send data to the previously addressed device
  123. TWDR = data;
  124. TWCR = (1<<TWINT) | (1<<TWEN);
  125. // wait until transmission completed
  126. while(!(TWCR & (1<<TWINT)));
  127. // check value of TWI Status Register. Mask prescaler bits
  128. twst = TW_STATUS & 0xF8;
  129. if( twst != TW_MT_DATA_ACK) return 1;
  130. return 0;
  131. }/* i2c_write */
  132. /*************************************************************************
  133. Read one byte from the I2C device, request more data from device
  134. Return: byte read from I2C device
  135. *************************************************************************/
  136. unsigned char i2c_readAck(void)
  137. {
  138. TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
  139. while(!(TWCR & (1<<TWINT)));
  140. return TWDR;
  141. }/* i2c_readAck */
  142. /*************************************************************************
  143. Read one byte from the I2C device, read is followed by a stop condition
  144. Return: byte read from I2C device
  145. *************************************************************************/
  146. unsigned char i2c_readNak(void)
  147. {
  148. TWCR = (1<<TWINT) | (1<<TWEN);
  149. while(!(TWCR & (1<<TWINT)));
  150. return TWDR;
  151. }/* i2c_readNak */