diff options
| author | Drashna Jaelre <drashna@live.com> | 2019-04-22 08:25:21 -0700 |
|---|---|---|
| committer | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2019-04-22 08:25:21 -0700 |
| commit | c7583d181a2cae24af60efa93caa3d662e5d48f4 (patch) | |
| tree | 3658e642bf154a3aca220d877c3b58a68b958bd5 | |
| parent | 76e78e8ca1a348e85b3e8f351fcb42d94a3634a4 (diff) | |
| download | qmk_firmware-c7583d181a2cae24af60efa93caa3d662e5d48f4.tar.gz qmk_firmware-c7583d181a2cae24af60efa93caa3d662e5d48f4.zip | |
Update handwired/frenchdev keyboard (#5443)
| -rw-r--r-- | keyboards/handwired/frenchdev/config.h | 5 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/frenchdev.c | 54 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/frenchdev.h | 8 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/i2cmaster.h | 178 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/keymaps/default/keymap.c | 152 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/matrix.c | 29 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/rules.mk | 6 | ||||
| -rw-r--r-- | keyboards/handwired/frenchdev/twimaster.c | 208 |
8 files changed, 115 insertions, 525 deletions
diff --git a/keyboards/handwired/frenchdev/config.h b/keyboards/handwired/frenchdev/config.h index b01eec7aa..eca669090 100644 --- a/keyboards/handwired/frenchdev/config.h +++ b/keyboards/handwired/frenchdev/config.h | |||
| @@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License | |||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #ifndef FRENCHDEV_V1_CONFIG_H | 18 | #pragma once |
| 19 | #define FRENCHDEV_V1_CONFIG_H | ||
| 20 | 19 | ||
| 21 | #include "config_common.h" | 20 | #include "config_common.h" |
| 22 | 21 | ||
| @@ -81,5 +80,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 81 | //#define NO_ACTION_MACRO | 80 | //#define NO_ACTION_MACRO |
| 82 | //#define NO_ACTION_FUNCTION | 81 | //#define NO_ACTION_FUNCTION |
| 83 | //#define DEBUG_MATRIX_SCAN_RATE | 82 | //#define DEBUG_MATRIX_SCAN_RATE |
| 84 | |||
| 85 | #endif //FRENCHDEV_V1_CONFIG_H | ||
diff --git a/keyboards/handwired/frenchdev/frenchdev.c b/keyboards/handwired/frenchdev/frenchdev.c index 6d5883a3a..6eed4de5f 100644 --- a/keyboards/handwired/frenchdev/frenchdev.c +++ b/keyboards/handwired/frenchdev/frenchdev.c | |||
| @@ -1,5 +1,26 @@ | |||
| 1 | #include "frenchdev.h" | 1 | #include "frenchdev.h" |
| 2 | #include "i2cmaster.h" | 2 | |
| 3 | extern inline void frenchdev_board_led_on(void); | ||
| 4 | extern inline void frenchdev_led_1_on(void); | ||
| 5 | extern inline void frenchdev_led_2_on(void); | ||
| 6 | extern inline void frenchdev_led_3_on(void); | ||
| 7 | extern inline void frenchdev_led_on(uint8_t led); | ||
| 8 | |||
| 9 | extern inline void frenchdev_board_led_off(void); | ||
| 10 | extern inline void frenchdev_led_1_off(void); | ||
| 11 | extern inline void frenchdev_led_2_off(void); | ||
| 12 | extern inline void frenchdev_led_3_off(void); | ||
| 13 | extern inline void frenchdev_led_off(uint8_t led); | ||
| 14 | |||
| 15 | extern inline void frenchdev_led_all_on(void); | ||
| 16 | extern inline void frenchdev_led_all_off(void); | ||
| 17 | |||
| 18 | extern inline void frenchdev_led_1_set(uint8_t n); | ||
| 19 | extern inline void frenchdev_led_2_set(uint8_t n); | ||
| 20 | extern inline void frenchdev_led_3_set(uint8_t n); | ||
| 21 | extern inline void frenchdev_led_set(uint8_t led, uint8_t n); | ||
| 22 | |||
| 23 | extern inline void frenchdev_led_all_set(uint8_t n); | ||
| 3 | 24 | ||
| 4 | bool i2c_initialized = 0; | 25 | bool i2c_initialized = 0; |
| 5 | uint8_t mcp23018_status = 0x20; | 26 | uint8_t mcp23018_status = 0x20; |
| @@ -31,15 +52,15 @@ void frenchdev_blink_all_leds(void) | |||
| 31 | frenchdev_led_all_off(); | 52 | frenchdev_led_all_off(); |
| 32 | frenchdev_led_all_set(LED_BRIGHTNESS_HI); | 53 | frenchdev_led_all_set(LED_BRIGHTNESS_HI); |
| 33 | frenchdev_led_1_on(); | 54 | frenchdev_led_1_on(); |
| 34 | _delay_ms(50); | 55 | wait_ms(50); |
| 35 | frenchdev_led_2_on(); | 56 | frenchdev_led_2_on(); |
| 36 | _delay_ms(50); | 57 | wait_ms(50); |
| 37 | frenchdev_led_3_on(); | 58 | frenchdev_led_3_on(); |
| 38 | _delay_ms(50); | 59 | wait_ms(50); |
| 39 | frenchdev_led_1_off(); | 60 | frenchdev_led_1_off(); |
| 40 | _delay_ms(50); | 61 | wait_ms(50); |
| 41 | frenchdev_led_2_off(); | 62 | frenchdev_led_2_off(); |
| 42 | _delay_ms(50); | 63 | wait_ms(50); |
| 43 | frenchdev_led_3_off(); | 64 | frenchdev_led_3_off(); |
| 44 | frenchdev_led_all_off(); | 65 | frenchdev_led_all_off(); |
| 45 | } | 66 | } |
| @@ -54,28 +75,28 @@ uint8_t init_mcp23018(void) { | |||
| 54 | // cli(); | 75 | // cli(); |
| 55 | if (i2c_initialized == 0) { | 76 | if (i2c_initialized == 0) { |
| 56 | i2c_init(); // on pins D(1,0) | 77 | i2c_init(); // on pins D(1,0) |
| 57 | i2c_initialized++; | 78 | i2c_initialized = true;; |
| 58 | _delay_ms(1000); | 79 | wait_ms(1000); |
| 59 | } | 80 | } |
| 60 | 81 | ||
| 61 | // set pin direction | 82 | // set pin direction |
| 62 | // - unused : input : 1 | 83 | // - unused : input : 1 |
| 63 | // - input : input : 1 | 84 | // - input : input : 1 |
| 64 | // - driving : output : 0 | 85 | // - driving : output : 0 |
| 65 | mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; | 86 | mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 66 | mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out; | 87 | mcp23018_status = i2c_write(IODIRA, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 67 | mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out; | 88 | mcp23018_status = i2c_write(0b00000000, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 68 | mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out; | 89 | mcp23018_status = i2c_write(0b00111111, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 69 | i2c_stop(); | 90 | i2c_stop(); |
| 70 | 91 | ||
| 71 | // set pull-up | 92 | // set pull-up |
| 72 | // - unused : on : 1 | 93 | // - unused : on : 1 |
| 73 | // - input : on : 1 | 94 | // - input : on : 1 |
| 74 | // - driving : off : 0 | 95 | // - driving : off : 0 |
| 75 | mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; | 96 | mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 76 | mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out; | 97 | mcp23018_status = i2c_write(GPPUA, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 77 | mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out; | 98 | mcp23018_status = i2c_write(0b00000000, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 78 | mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out; | 99 | mcp23018_status = i2c_write(0b00111111, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 79 | 100 | ||
| 80 | out: | 101 | out: |
| 81 | i2c_stop(); | 102 | i2c_stop(); |
| @@ -84,4 +105,3 @@ out: | |||
| 84 | 105 | ||
| 85 | return mcp23018_status; | 106 | return mcp23018_status; |
| 86 | } | 107 | } |
| 87 | |||
diff --git a/keyboards/handwired/frenchdev/frenchdev.h b/keyboards/handwired/frenchdev/frenchdev.h index 82dbe18b8..1df399088 100644 --- a/keyboards/handwired/frenchdev/frenchdev.h +++ b/keyboards/handwired/frenchdev/frenchdev.h | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | #ifndef FRENCHDEV_V1_H | 1 | #pragma once |
| 2 | #define FRENCHDEV_V1_H | ||
| 3 | 2 | ||
| 4 | #include "quantum.h" | 3 | #include "quantum.h" |
| 5 | #include <stdint.h> | 4 | #include <stdint.h> |
| 6 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 7 | #include "i2cmaster.h" | 6 | #include "i2c_master.h" |
| 8 | #include <util/delay.h> | 7 | #include <util/delay.h> |
| 9 | 8 | ||
| 10 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) | 9 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) |
| @@ -24,6 +23,7 @@ | |||
| 24 | #define OLATB 0x15 | 23 | #define OLATB 0x15 |
| 25 | 24 | ||
| 26 | extern uint8_t mcp23018_status; | 25 | extern uint8_t mcp23018_status; |
| 26 | #define I2C_TIMEOUT 100 | ||
| 27 | 27 | ||
| 28 | void init_frenchdev(void); | 28 | void init_frenchdev(void); |
| 29 | void frenchdev_blink_all_leds(void); | 29 | void frenchdev_blink_all_leds(void); |
| @@ -111,5 +111,3 @@ inline void frenchdev_led_all_set(uint8_t n) | |||
| 111 | { k51, k41, k31, k21, k11, k01 }, \ | 111 | { k51, k41, k31, k21, k11, k01 }, \ |
| 112 | { k50, k40, k30, k20, k10, KC_NO } \ | 112 | { k50, k40, k30, k20, k10, KC_NO } \ |
| 113 | } | 113 | } |
| 114 | |||
| 115 | #endif | ||
diff --git a/keyboards/handwired/frenchdev/i2cmaster.h b/keyboards/handwired/frenchdev/i2cmaster.h deleted file mode 100644 index 3917b9e6c..000000000 --- a/keyboards/handwired/frenchdev/i2cmaster.h +++ /dev/null | |||
| @@ -1,178 +0,0 @@ | |||
| 1 | #ifndef _I2CMASTER_H | ||
| 2 | #define _I2CMASTER_H 1 | ||
| 3 | /************************************************************************* | ||
| 4 | * Title: C include file for the I2C master interface | ||
| 5 | * (i2cmaster.S or twimaster.c) | ||
| 6 | * Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury | ||
| 7 | * File: $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $ | ||
| 8 | * Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 | ||
| 9 | * Target: any AVR device | ||
| 10 | * Usage: see Doxygen manual | ||
| 11 | **************************************************************************/ | ||
| 12 | |||
| 13 | #ifdef DOXYGEN | ||
| 14 | /** | ||
| 15 | @defgroup pfleury_ic2master I2C Master library | ||
| 16 | @code #include <i2cmaster.h> @endcode | ||
| 17 | |||
| 18 | @brief I2C (TWI) Master Software Library | ||
| 19 | |||
| 20 | Basic routines for communicating with I2C slave devices. This single master | ||
| 21 | implementation is limited to one bus master on the I2C bus. | ||
| 22 | |||
| 23 | This I2c library is implemented as a compact assembler software implementation of the I2C protocol | ||
| 24 | which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (twimaster.c). | ||
| 25 | Since the API for these two implementations is exactly the same, an application can be linked either against the | ||
| 26 | software I2C implementation or the hardware I2C implementation. | ||
| 27 | |||
| 28 | Use 4.7k pull-up resistor on the SDA and SCL pin. | ||
| 29 | |||
| 30 | Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module | ||
| 31 | i2cmaster.S to your target when using the software I2C implementation ! | ||
| 32 | |||
| 33 | Adjust the CPU clock frequence F_CPU in twimaster.c or in the Makfile when using the TWI hardware implementaion. | ||
| 34 | |||
| 35 | @note | ||
| 36 | The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted | ||
| 37 | to GNU assembler and AVR-GCC C call interface. | ||
| 38 | Replaced the incorrect quarter period delays found in AVR300 with | ||
| 39 | half period delays. | ||
| 40 | |||
| 41 | @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury | ||
| 42 | |||
| 43 | @par API Usage Example | ||
| 44 | The following code shows typical usage of this library, see example test_i2cmaster.c | ||
| 45 | |||
| 46 | @code | ||
| 47 | |||
| 48 | #include <i2cmaster.h> | ||
| 49 | |||
| 50 | |||
| 51 | #define Dev24C02 0xA2 // device address of EEPROM 24C02, see datasheet | ||
| 52 | |||
| 53 | int main(void) | ||
| 54 | { | ||
| 55 | unsigned char ret; | ||
| 56 | |||
| 57 | i2c_init(); // initialize I2C library | ||
| 58 | |||
| 59 | // write 0x75 to EEPROM address 5 (Byte Write) | ||
| 60 | i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode | ||
| 61 | i2c_write(0x05); // write address = 5 | ||
| 62 | i2c_write(0x75); // write value 0x75 to EEPROM | ||
| 63 | i2c_stop(); // set stop conditon = release bus | ||
| 64 | |||
| 65 | |||
| 66 | // read previously written value back from EEPROM address 5 | ||
| 67 | i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode | ||
| 68 | |||
| 69 | i2c_write(0x05); // write address = 5 | ||
| 70 | i2c_rep_start(Dev24C02+I2C_READ); // set device address and read mode | ||
| 71 | |||
| 72 | ret = i2c_readNak(); // read one byte from EEPROM | ||
| 73 | i2c_stop(); | ||
| 74 | |||
| 75 | for(;;); | ||
| 76 | } | ||
| 77 | @endcode | ||
| 78 | |||
| 79 | */ | ||
| 80 | #endif /* DOXYGEN */ | ||
| 81 | |||
| 82 | /**@{*/ | ||
| 83 | |||
| 84 | #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 | ||
| 85 | #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" | ||
| 86 | #endif | ||
| 87 | |||
| 88 | #include <avr/io.h> | ||
| 89 | |||
| 90 | /** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */ | ||
| 91 | #define I2C_READ 1 | ||
| 92 | |||
| 93 | /** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */ | ||
| 94 | #define I2C_WRITE 0 | ||
| 95 | |||
| 96 | |||
| 97 | /** | ||
| 98 | @brief initialize the I2C master interace. Need to be called only once | ||
| 99 | @param void | ||
| 100 | @return none | ||
| 101 | */ | ||
| 102 | extern void i2c_init(void); | ||
| 103 | |||
| 104 | |||
| 105 | /** | ||
| 106 | @brief Terminates the data transfer and releases the I2C bus | ||
| 107 | @param void | ||
| 108 | @return none | ||
| 109 | */ | ||
| 110 | extern void i2c_stop(void); | ||
| 111 | |||
| 112 | |||
| 113 | /** | ||
| 114 | @brief Issues a start condition and sends address and transfer direction | ||
| 115 | |||
| 116 | @param addr address and transfer direction of I2C device | ||
| 117 | @retval 0 device accessible | ||
| 118 | @retval 1 failed to access device | ||
| 119 | */ | ||
| 120 | extern unsigned char i2c_start(unsigned char addr); | ||
| 121 | |||
| 122 | |||
| 123 | /** | ||
| 124 | @brief Issues a repeated start condition and sends address and transfer direction | ||
| 125 | |||
| 126 | @param addr address and transfer direction of I2C device | ||
| 127 | @retval 0 device accessible | ||
| 128 | @retval 1 failed to access device | ||
| 129 | */ | ||
| 130 | extern unsigned char i2c_rep_start(unsigned char addr); | ||
| 131 | |||
| 132 | |||
| 133 | /** | ||
| 134 | @brief Issues a start condition and sends address and transfer direction | ||
| 135 | |||
| 136 | If device is busy, use ack polling to wait until device ready | ||
| 137 | @param addr address and transfer direction of I2C device | ||
| 138 | @return none | ||
| 139 | */ | ||
| 140 | extern void i2c_start_wait(unsigned char addr); | ||
| 141 | |||
| 142 | |||
| 143 | /** | ||
| 144 | @brief Send one byte to I2C device | ||
| 145 | @param data byte to be transfered | ||
| 146 | @retval 0 write successful | ||
| 147 | @retval 1 write failed | ||
| 148 | */ | ||
| 149 | extern unsigned char i2c_write(unsigned char data); | ||
| 150 | |||
| 151 | |||
| 152 | /** | ||
| 153 | @brief read one byte from the I2C device, request more data from device | ||
| 154 | @return byte read from I2C device | ||
| 155 | */ | ||
| 156 | extern unsigned char i2c_readAck(void); | ||
| 157 | |||
| 158 | /** | ||
| 159 | @brief read one byte from the I2C device, read is followed by a stop condition | ||
| 160 | @return byte read from I2C device | ||
| 161 | */ | ||
| 162 | extern unsigned char i2c_readNak(void); | ||
| 163 | |||
| 164 | /** | ||
| 165 | @brief read one byte from the I2C device | ||
| 166 | |||
| 167 | Implemented as a macro, which calls either i2c_readAck or i2c_readNak | ||
| 168 | |||
| 169 | @param ack 1 send ack, request more data from device<br> | ||
| 170 | 0 send nak, read is followed by a stop condition | ||
| 171 | @return byte read from I2C device | ||
| 172 | */ | ||
| 173 | extern unsigned char i2c_read(unsigned char ack); | ||
| 174 | #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); | ||
| 175 | |||
| 176 | |||
| 177 | /**@}*/ | ||
| 178 | #endif | ||
diff --git a/keyboards/handwired/frenchdev/keymaps/default/keymap.c b/keyboards/handwired/frenchdev/keymaps/default/keymap.c index 506383a1b..7b82f36e3 100644 --- a/keyboards/handwired/frenchdev/keymaps/default/keymap.c +++ b/keyboards/handwired/frenchdev/keymaps/default/keymap.c | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #include QMK_KEYBOARD_H | 1 | #include QMK_KEYBOARD_H |
| 2 | #include "mousekey.h" | ||
| 3 | #include "keymap_bepo.h" | 2 | #include "keymap_bepo.h" |
| 4 | 3 | ||
| 5 | 4 | ||
| @@ -14,7 +13,7 @@ | |||
| 14 | #define KEY_DELAY 130 | 13 | #define KEY_DELAY 130 |
| 15 | 14 | ||
| 16 | enum macros { | 15 | enum macros { |
| 17 | M_LP, // left pedal | 16 | M_LP = SAFE_RANGE, // left pedal |
| 18 | M_RP, // right pedal | 17 | M_RP, // right pedal |
| 19 | M_SF, // shift | 18 | M_SF, // shift |
| 20 | M_SFS, // shift and space | 19 | M_SFS, // shift and space |
| @@ -63,19 +62,18 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 63 | * |------+------| / |------| , | space|------|------|------ .. ------|------|------| L1/sp| LEFT |------| UP |------+------| * | 62 | * |------+------| / |------| , | space|------|------|------ .. ------|------|------| L1/sp| LEFT |------| UP |------+------| * |
| 64 | * | CTRL | win |------/ \-------------| L1 | alt | .. | CAPS | L1 |-------------/ \------| : | CTRL | * | 63 | * | CTRL | win |------/ \-------------| L1 | alt | .. | CAPS | L1 |-------------/ \------| : | CTRL | * |
| 65 | * `-------------/ \-------------/ .. \-------------/ \-------------/ * | 64 | * `-------------/ \-------------/ .. \-------------/ \-------------/ * |
| 66 | *M(M_LP) | ||
| 67 | */ | 65 | */ |
| 68 | [_BASE] = LAYOUT( | 66 | [_BASE] = LAYOUT( |
| 69 | KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \ | 67 | KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \ |
| 70 | KC_ESC, BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_DTRM, BP_DCRC, BP_AT, BP_PLUS, BP_MINS, BP_SLSH, BP_ASTR, KC_BSPC, \ | 68 | KC_ESC, BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_DTRM, BP_DCRC, BP_AT, BP_PLUS, BP_MINS, BP_SLSH, BP_ASTR, KC_BSPC, \ |
| 71 | KC_TAB, BP_B, BP_ECUT, BP_O, BP_P, BP_EGRV, BP_UNDS, BP_EQL, BP_K, BP_V, BP_D, BP_L, BP_J, KC_ENT, \ | 69 | KC_TAB, BP_B, BP_ECUT, BP_O, BP_P, BP_EGRV, BP_UNDS, BP_EQL, BP_K, BP_V, BP_D, BP_L, BP_J, KC_ENT, \ |
| 72 | BP_GRV, BP_A, BP_U, BP_E, BP_I, BP_F, BP_SCLN, BP_EXLM, BP_C, BP_T, BP_S, BP_R, BP_N, BP_APOS, \ | 70 | BP_GRV, BP_A, BP_U, BP_E, BP_I, BP_F, BP_SCLN, BP_EXLM, BP_C, BP_T, BP_S, BP_R, BP_N, BP_APOS, \ |
| 73 | M(M_SF), BP_Z, BP_AGRV, BP_Y, BP_X, KC_RBRACKET, M(M_SFS), BP_CBSP, M(L2INS), M(L2LOC), BP_CDEL, M(M_SFS),BP_M, BP_G, KC_UP, BP_H, BP_Q, M(M_SF), \ | 71 | M_SF, BP_Z, BP_AGRV, BP_Y, BP_X, KC_RBRC, M_SFS, BP_CBSP, L2INS, L2LOC, BP_CDEL, M_SFS, BP_M, BP_G, KC_UP, BP_H, BP_Q, M_SF, \ |
| 74 | KC_LCTL, KC_LGUI, KC_PSLS, BP_DOT, BP_COMM, KC_SPACE,M(M_L1E), KC_LALT, KC_CAPS, M(M_L1E),KC_SPACE,KC_LEFT, KC_DOWN, KC_RIGHT,BP_COLN, KC_RCTL, \ | 72 | KC_LCTL, KC_LGUI, KC_PSLS, BP_DOT, BP_COMM, KC_SPACE,M_L1E, KC_LALT, KC_CAPS, M_L1E, KC_SPACE, KC_LEFT, KC_DOWN, KC_RIGHT,BP_COLN, KC_RCTL, \ |
| 75 | //left pedals | 73 | //left pedals |
| 76 | M(M_LP), M(M_RP), KC_TRNS, \ | 74 | M_LP, M_RP, KC_TRNS, \ |
| 77 | //right pedals | 75 | //right pedals |
| 78 | M(M_LP), M(M_RP), KC_TRNS \ | 76 | M_LP, M_RP, KC_TRNS \ |
| 79 | ), | 77 | ), |
| 80 | 78 | ||
| 81 | /* Larer 1 for symbols. | 79 | /* Larer 1 for symbols. |
| @@ -102,7 +100,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 102 | KC_TRNS, BP_DCUR, BP_PARG, BP_SECT, BP_DGRK, KC_TRNS, BP_TILD, BP_DCAR, BP_LEQL, BP_GEQL, BP_PSMS, BP_OBEL, BP_TIMS, KC_TRNS, \ | 100 | KC_TRNS, BP_DCUR, BP_PARG, BP_SECT, BP_DGRK, KC_TRNS, BP_TILD, BP_DCAR, BP_LEQL, BP_GEQL, BP_PSMS, BP_OBEL, BP_TIMS, KC_TRNS, \ |
| 103 | KC_TRNS, BP_BSLS, BP_ASTR, BP_LCBR, BP_RCBR, BP_GRV, KC_TRNS, BP_DIFF, BP_HASH, BP_LBRC, BP_RBRC, BP_PERC, BP_PMIL, KC_TRNS, \ | 101 | KC_TRNS, BP_BSLS, BP_ASTR, BP_LCBR, BP_RCBR, BP_GRV, KC_TRNS, BP_DIFF, BP_HASH, BP_LBRC, BP_RBRC, BP_PERC, BP_PMIL, KC_TRNS, \ |
| 104 | KC_TRNS, BP_EQL, BP_UGRV, BP_LPRN, BP_RPRN, BP_PLUS, BP_COLN, BP_QEST, BP_CCED, BP_LESS, BP_GRTR, BP_AMPR, BP_UNDS, KC_TRNS, \ | 102 | KC_TRNS, BP_EQL, BP_UGRV, BP_LPRN, BP_RPRN, BP_PLUS, BP_COLN, BP_QEST, BP_CCED, BP_LESS, BP_GRTR, BP_AMPR, BP_UNDS, KC_TRNS, \ |
| 105 | KC_TRNS, M(M_UN), M(M_CUT),M(M_CP), M(M_PS), M(M_SE), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, BP_DLR, BP_EQL, KC_PGUP, BP_PIPE, BP_SLSH, KC_TRNS, \ | 103 | KC_TRNS, M_UN, M_CUT, M_CP, M_PS, M_SE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, BP_DLR, BP_EQL, KC_PGUP, BP_PIPE, BP_SLSH, KC_TRNS, \ |
| 106 | KC_TRNS, KC_TRNS, BP_BSLS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END, KC_TRNS, KC_TRNS, \ | 104 | KC_TRNS, KC_TRNS, BP_BSLS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END, KC_TRNS, KC_TRNS, \ |
| 107 | //left pedals | 105 | //left pedals |
| 108 | KC_TRNS, KC_BTN1, KC_TRNS, \ | 106 | KC_TRNS, KC_BTN1, KC_TRNS, \ |
| @@ -134,12 +132,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 134 | KC_TRNS, KC_TRNS, KC_TRNS, KC_MSTP, KC_MPRV, KC_MNXT, KC_MPLY, KC_MPLY, KC_MPRV, KC_MNXT, KC_MSTP, KC_TRNS, KC_PMNS, KC_TRNS, \ | 132 | KC_TRNS, KC_TRNS, KC_TRNS, KC_MSTP, KC_MPRV, KC_MNXT, KC_MPLY, KC_MPLY, KC_MPRV, KC_MNXT, KC_MSTP, KC_TRNS, KC_PMNS, KC_TRNS, \ |
| 135 | KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_U, KC_TRNS, KC_BTN4, KC_BTN5, KC_BTN4, KC_BTN5, KC_KP_7, KC_KP_8, KC_KP_9, KC_PPLS, KC_TRNS, \ | 133 | KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_U, KC_TRNS, KC_BTN4, KC_BTN5, KC_BTN4, KC_BTN5, KC_KP_7, KC_KP_8, KC_KP_9, KC_PPLS, KC_TRNS, \ |
| 136 | KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_D, KC_BTN3, KC_BTN2, KC_BTN1, KC_BTN1, KC_BTN2, KC_KP_4, KC_KP_5, KC_KP_6, KC_PAST, KC_TRNS, \ | 134 | KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_D, KC_BTN3, KC_BTN2, KC_BTN1, KC_BTN1, KC_BTN2, KC_KP_4, KC_KP_5, KC_KP_6, KC_PAST, KC_TRNS, \ |
| 137 | KC_TRNS, M(M_UN), M(M_CUT),M(M_CP), M(M_PS), KC_BTN3, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_KP_1, KC_KP_2, KC_KP_3, KC_PSLS, KC_TRNS, \ | 135 | KC_TRNS, M_UN, M_CUT, M_CP, M_PS, KC_BTN3, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_KP_1, KC_KP_2, KC_KP_3, KC_PSLS, KC_TRNS, \ |
| 138 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_0, KC_PDOT, BP_DOT, BP_COMM, KC_TRNS, \ | 136 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_0, KC_PDOT, BP_DOT, BP_COMM, KC_TRNS, \ |
| 139 | //left pedals | 137 | //left pedals |
| 140 | KC_BTN3, M(M_RP), KC_TRNS, \ | 138 | KC_BTN3, M_RP, KC_TRNS, \ |
| 141 | //right pedals | 139 | //right pedals |
| 142 | KC_BTN3, M(M_RP), KC_TRNS \ | 140 | KC_BTN3, M_RP, KC_TRNS \ |
| 143 | ), | 141 | ), |
| 144 | 142 | ||
| 145 | /* TRNS - skeleton for laters | 143 | /* TRNS - skeleton for laters |
| @@ -169,9 +167,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 169 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ | 167 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ |
| 170 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ | 168 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ |
| 171 | //left pedals | 169 | //left pedals |
| 172 | KC_BTN3, M(M_RP), KC_TRNS, \ | 170 | KC_BTN3, M_RP, KC_TRNS, \ |
| 173 | //right pedals | 171 | //right pedals |
| 174 | KC_BTN3, M(M_RP), KC_TRNS \ | 172 | KC_BTN3, M_RP, KC_TRNS \ |
| 175 | ), | 173 | ), |
| 176 | 174 | ||
| 177 | }; | 175 | }; |
| @@ -191,28 +189,52 @@ void release_shift(void) { | |||
| 191 | 189 | ||
| 192 | void press_space(void) { | 190 | void press_space(void) { |
| 193 | if(shift_count > 0) unregister_code (KC_LSHIFT); | 191 | if(shift_count > 0) unregister_code (KC_LSHIFT); |
| 194 | register_code (KC_SPACE); | 192 | tap_code(KC_SPACE); |
| 195 | unregister_code (KC_SPACE); | ||
| 196 | if(shift_count > 0) register_code (KC_LSHIFT); | 193 | if(shift_count > 0) register_code (KC_LSHIFT); |
| 197 | } | 194 | } |
| 198 | 195 | ||
| 199 | void press_enter(void) { | 196 | void press_enter(void) { |
| 200 | if(shift_count > 0) unregister_code (KC_LSHIFT); | 197 | if(shift_count > 0) unregister_code (KC_LSHIFT); |
| 201 | register_code (KC_ENT); | 198 | tap_code (KC_ENT); |
| 202 | unregister_code (KC_ENT); | ||
| 203 | if(shift_count > 0) register_code (KC_LSHIFT); | 199 | if(shift_count > 0) register_code (KC_LSHIFT); |
| 204 | } | 200 | } |
| 205 | 201 | ||
| 206 | void press_underscore(void) { | 202 | void press_underscore(void) { |
| 207 | if(shift_count > 0) unregister_code (KC_LSHIFT); | 203 | if(shift_count > 0) unregister_code (KC_LSHIFT); |
| 208 | register_code ((unsigned char) BP_UNDS); | 204 | tap_code ((unsigned char) BP_UNDS); |
| 209 | unregister_code ((unsigned char) BP_UNDS); | ||
| 210 | if(shift_count > 0) register_code (KC_LSHIFT); | 205 | if(shift_count > 0) register_code (KC_LSHIFT); |
| 211 | } | 206 | } |
| 212 | 207 | ||
| 213 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | 208 | void matrix_init_user(void) { |
| 214 | { | 209 | } |
| 215 | switch(id) { | 210 | |
| 211 | // Bleah globals need to be initialized. | ||
| 212 | uint8_t old_layer=_BASE; | ||
| 213 | |||
| 214 | void matrix_scan_user(void) { | ||
| 215 | uint8_t layer = biton32(layer_state); | ||
| 216 | |||
| 217 | frenchdev_led_1_off(); | ||
| 218 | frenchdev_led_2_off(); | ||
| 219 | switch (layer) { | ||
| 220 | case _BASE: | ||
| 221 | frenchdev_led_2_on(); | ||
| 222 | break; | ||
| 223 | case _SYMBOLS: | ||
| 224 | frenchdev_led_1_on(); | ||
| 225 | break; | ||
| 226 | case _MEDIA: | ||
| 227 | frenchdev_led_1_on(); | ||
| 228 | frenchdev_led_2_on(); | ||
| 229 | default: | ||
| 230 | // none | ||
| 231 | break; | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | |||
| 236 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 237 | switch(keycode) { | ||
| 216 | case M_LP: //left pedal | 238 | case M_LP: //left pedal |
| 217 | if (record->event.pressed) { | 239 | if (record->event.pressed) { |
| 218 | layer_on(1); | 240 | layer_on(1); |
| @@ -220,25 +242,19 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | |||
| 220 | key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer. | 242 | key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer. |
| 221 | } else { | 243 | } else { |
| 222 | if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) { | 244 | if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) { |
| 223 | mousekey_on (KC_BTN2); | 245 | tap_code (KC_BTN2); |
| 224 | mousekey_send(); | ||
| 225 | mousekey_off (KC_BTN2); | ||
| 226 | mousekey_send(); | ||
| 227 | } | 246 | } |
| 228 | unregister_code (KC_SLCK); | 247 | unregister_code (KC_SLCK); |
| 229 | layer_off(1); | 248 | layer_off(1); |
| 230 | } | 249 | } |
| 231 | break; | 250 | break; |
| 232 | case M_RP: //right pedal | 251 | case M_RP: //right pedal |
| 233 | if (record->event.pressed) { | 252 | if (record->event.pressed) { |
| 234 | layer_on(2); | 253 | layer_on(2); |
| 235 | key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer. | 254 | key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer. |
| 236 | } else { | 255 | } else { |
| 237 | if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) { | 256 | if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) { |
| 238 | mousekey_on (KC_BTN1); | 257 | tap_code (KC_BTN1); |
| 239 | mousekey_send(); | ||
| 240 | mousekey_off (KC_BTN1); | ||
| 241 | mousekey_send(); | ||
| 242 | } | 258 | } |
| 243 | layer_off(2); | 259 | layer_off(2); |
| 244 | } | 260 | } |
| @@ -289,13 +305,12 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | |||
| 289 | key_timer_2 = timer_read(); // if the key is being pressed, we start the timer. | 305 | key_timer_2 = timer_read(); // if the key is being pressed, we start the timer. |
| 290 | } else { | 306 | } else { |
| 291 | if (timer_elapsed(key_timer_2) < KEY_DELAY) { | 307 | if (timer_elapsed(key_timer_2) < KEY_DELAY) { |
| 292 | register_code (KC_INS); | 308 | tap_code (KC_INS); |
| 293 | unregister_code (KC_INS); | ||
| 294 | } | 309 | } |
| 295 | l2_locked = 0; | 310 | l2_locked = 0; |
| 296 | layer_off(2); | 311 | layer_off(2); |
| 297 | } | 312 | } |
| 298 | break; | 313 | break; |
| 299 | case L2LOC: //lock L2 | 314 | case L2LOC: //lock L2 |
| 300 | if (record->event.pressed) { | 315 | if (record->event.pressed) { |
| 301 | key_timer_2 = timer_read(); // if the key is being pressed, we start the timer. | 316 | key_timer_2 = timer_read(); // if the key is being pressed, we start the timer. |
| @@ -309,80 +324,33 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | |||
| 309 | layer_off(2); | 324 | layer_off(2); |
| 310 | } | 325 | } |
| 311 | } | 326 | } |
| 312 | break; | 327 | break; |
| 313 | case M_UN: // undo | 328 | case M_UN: // undo |
| 314 | if (record->event.pressed) { | 329 | if (record->event.pressed) { |
| 315 | register_code(KC_LCTL); | 330 | tap_code16(C(BP_Z)); |
| 316 | register_code(BP_Z); | ||
| 317 | unregister_code(BP_Z); | ||
| 318 | unregister_code(KC_LCTL); | ||
| 319 | } | 331 | } |
| 320 | break; | 332 | break; |
| 321 | case M_CUT: // cut | 333 | case M_CUT: // cut |
| 322 | if (record->event.pressed) { | 334 | if (record->event.pressed) { |
| 323 | register_code(KC_LCTL); | 335 | tap_code16(C(BP_X)); |
| 324 | register_code(BP_X); | ||
| 325 | unregister_code(BP_X); | ||
| 326 | unregister_code(KC_LCTL); | ||
| 327 | } | 336 | } |
| 328 | break; | 337 | break; |
| 329 | case M_CP: // copy | 338 | case M_CP: // copy |
| 330 | if (record->event.pressed) { | 339 | if (record->event.pressed) { |
| 331 | register_code(KC_LCTL); | 340 | tap_code16(C(BP_C)); |
| 332 | register_code(BP_C); | ||
| 333 | unregister_code(BP_C); | ||
| 334 | unregister_code(KC_LCTL); | ||
| 335 | } | 341 | } |
| 336 | break; | 342 | break; |
| 337 | case M_PS: // paste | 343 | case M_PS: // paste |
| 338 | if (record->event.pressed) { | 344 | if (record->event.pressed) { |
| 339 | register_code(KC_LCTL); | 345 | tap_code16(C(BP_V)); |
| 340 | register_code(BP_V); | ||
| 341 | unregister_code(BP_V); | ||
| 342 | unregister_code(KC_LCTL); | ||
| 343 | } | 346 | } |
| 344 | break; | 347 | break; |
| 345 | case M_SE: // search | 348 | case M_SE: // search |
| 346 | if (record->event.pressed) { | 349 | if (record->event.pressed) { |
| 347 | register_code(KC_LCTL); | 350 | tap_code16(C(BP_F)); |
| 348 | register_code(BP_F); | ||
| 349 | unregister_code(BP_F); | ||
| 350 | unregister_code(KC_LCTL); | ||
| 351 | } | 351 | } |
| 352 | break; | 352 | break; |
| 353 | } | 353 | } |
| 354 | return MACRO_NONE; | ||
| 355 | }; | ||
| 356 | |||
| 357 | void matrix_init_user(void) { | ||
| 358 | } | ||
| 359 | |||
| 360 | // Bleah globals need to be initialized. | ||
| 361 | uint8_t old_layer=_BASE; | ||
| 362 | |||
| 363 | void matrix_scan_user(void) { | ||
| 364 | uint8_t layer = biton32(layer_state); | ||
| 365 | |||
| 366 | frenchdev_led_1_off(); | ||
| 367 | frenchdev_led_2_off(); | ||
| 368 | switch (layer) { | ||
| 369 | case _BASE: | ||
| 370 | frenchdev_led_2_on(); | ||
| 371 | break; | ||
| 372 | case _SYMBOLS: | ||
| 373 | frenchdev_led_1_on(); | ||
| 374 | break; | ||
| 375 | case _MEDIA: | ||
| 376 | frenchdev_led_1_on(); | ||
| 377 | frenchdev_led_2_on(); | ||
| 378 | default: | ||
| 379 | // none | ||
| 380 | break; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | |||
| 385 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 386 | return true; | 354 | return true; |
| 387 | } | 355 | } |
| 388 | 356 | ||
diff --git a/keyboards/handwired/frenchdev/matrix.c b/keyboards/handwired/frenchdev/matrix.c index 7fe3d0bbf..4263555e9 100644 --- a/keyboards/handwired/frenchdev/matrix.c +++ b/keyboards/handwired/frenchdev/matrix.c | |||
| @@ -40,7 +40,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 40 | #include "util.h" | 40 | #include "util.h" |
| 41 | #include "matrix.h" | 41 | #include "matrix.h" |
| 42 | #include "frenchdev.h" | 42 | #include "frenchdev.h" |
| 43 | #include "i2cmaster.h" | ||
| 44 | #ifdef DEBUG_MATRIX_SCAN_RATE | 43 | #ifdef DEBUG_MATRIX_SCAN_RATE |
| 45 | #include "timer.h" | 44 | #include "timer.h" |
| 46 | #endif | 45 | #endif |
| @@ -280,11 +279,12 @@ static matrix_row_t read_cols(uint8_t row) | |||
| 280 | return 0; | 279 | return 0; |
| 281 | } else { | 280 | } else { |
| 282 | uint8_t data = 0; | 281 | uint8_t data = 0; |
| 283 | mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; | 282 | mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 284 | mcp23018_status = i2c_write(GPIOB); if (mcp23018_status) goto out; | 283 | mcp23018_status = i2c_write(GPIOB, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 285 | mcp23018_status = i2c_start(I2C_ADDR_READ); if (mcp23018_status) goto out; | 284 | mcp23018_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 286 | data = i2c_readNak(); | 285 | data = i2c_read_nack(I2C_TIMEOUT); if (mcp23018_status < 0) goto out; |
| 287 | data = ~data; | 286 | data = ~((uint8_t)mcp23018_status); |
| 287 | mcp23018_status = I2C_STATUS_SUCCESS; | ||
| 288 | out: | 288 | out: |
| 289 | i2c_stop(); | 289 | i2c_stop(); |
| 290 | return data; | 290 | return data; |
| @@ -318,11 +318,9 @@ static void unselect_rows(void) | |||
| 318 | // do nothing | 318 | // do nothing |
| 319 | } else { | 319 | } else { |
| 320 | // set all rows hi-Z : 1 | 320 | // set all rows hi-Z : 1 |
| 321 | mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; | 321 | mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 322 | mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out; | 322 | mcp23018_status = i2c_write(GPIOA, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 323 | mcp23018_status = i2c_write( 0xFF | 323 | mcp23018_status = i2c_write( 0xFF & ~(0<<8), I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 324 | & ~(0<<8) | ||
| 325 | ); if (mcp23018_status) goto out; | ||
| 326 | out: | 324 | out: |
| 327 | i2c_stop(); | 325 | i2c_stop(); |
| 328 | } | 326 | } |
| @@ -346,11 +344,9 @@ static void select_row(uint8_t row) | |||
| 346 | } else { | 344 | } else { |
| 347 | // set active row low : 0 | 345 | // set active row low : 0 |
| 348 | // set other rows hi-Z : 1 | 346 | // set other rows hi-Z : 1 |
| 349 | mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; | 347 | mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 350 | mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out; | 348 | mcp23018_status = i2c_write(GPIOA, I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 351 | mcp23018_status = i2c_write( 0xFF & ~(1<<row) | 349 | mcp23018_status = i2c_write( 0xFF & ~(1<<row) & ~(0<<8), I2C_TIMEOUT); if (mcp23018_status) goto out; |
| 352 | & ~(0<<8) | ||
| 353 | ); if (mcp23018_status) goto out; | ||
| 354 | out: | 350 | out: |
| 355 | i2c_stop(); | 351 | i2c_stop(); |
| 356 | } | 352 | } |
| @@ -393,4 +389,3 @@ static void select_row(uint8_t row) | |||
| 393 | } | 389 | } |
| 394 | } | 390 | } |
| 395 | } | 391 | } |
| 396 | |||
diff --git a/keyboards/handwired/frenchdev/rules.mk b/keyboards/handwired/frenchdev/rules.mk index c82bf4a38..69a12b68d 100644 --- a/keyboards/handwired/frenchdev/rules.mk +++ b/keyboards/handwired/frenchdev/rules.mk | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | #---------------------------------------------------------------------------- | 15 | #---------------------------------------------------------------------------- |
| 16 | 16 | ||
| 17 | # # project specific files | 17 | # # project specific files |
| 18 | SRC = twimaster.c \ | 18 | SRC = i2c_master.c \ |
| 19 | matrix.c | 19 | matrix.c |
| 20 | 20 | ||
| 21 | # MCU name | 21 | # MCU name |
| @@ -64,8 +64,7 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | |||
| 64 | # Atmel DFU loader 4096 | 64 | # Atmel DFU loader 4096 |
| 65 | # LUFA bootloader 4096 | 65 | # LUFA bootloader 4096 |
| 66 | # USBaspLoader 2048 | 66 | # USBaspLoader 2048 |
| 67 | OPT_DEFS += -DBOOTLOADER_SIZE=512 | 67 | BOOTLOADER = halfKay |
| 68 | |||
| 69 | 68 | ||
| 70 | # Build Options | 69 | # Build Options |
| 71 | # comment out to disable the options. | 70 | # comment out to disable the options. |
| @@ -86,4 +85,3 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | |||
| 86 | AUDIO_ENABLE = no # Audio output on port C6 | 85 | AUDIO_ENABLE = no # Audio output on port C6 |
| 87 | RGBLIGHT_ENABLE = no | 86 | RGBLIGHT_ENABLE = no |
| 88 | API_SYSEX_ENABLE = no | 87 | API_SYSEX_ENABLE = no |
| 89 | |||
diff --git a/keyboards/handwired/frenchdev/twimaster.c b/keyboards/handwired/frenchdev/twimaster.c deleted file mode 100644 index f91c08e6e..000000000 --- a/keyboards/handwired/frenchdev/twimaster.c +++ /dev/null | |||
| @@ -1,208 +0,0 @@ | |||
| 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 | |||
| 12 | #include <i2cmaster.h> | ||
| 13 | |||
| 14 | |||
| 15 | /* define CPU frequency in Mhz here if not defined in Makefile */ | ||
| 16 | #ifndef F_CPU | ||
| 17 | #define F_CPU 16000000UL | ||
| 18 | #endif | ||
| 19 | |||
| 20 | /* I2C clock in Hz */ | ||
| 21 | #define SCL_CLOCK 400000L | ||
| 22 | |||
| 23 | |||
| 24 | /************************************************************************* | ||
| 25 | Initialization of the I2C bus interface. Need to be called only once | ||
| 26 | *************************************************************************/ | ||
| 27 | void i2c_init(void) | ||
| 28 | { | ||
| 29 | /* initialize TWI clock | ||
| 30 | * minimal values in Bit Rate Register (TWBR) and minimal Prescaler | ||
| 31 | * bits in the TWI Status Register should give us maximal possible | ||
| 32 | * I2C bus speed - about 444 kHz | ||
| 33 | * | ||
| 34 | * for more details, see 20.5.2 in ATmega16/32 secification | ||
| 35 | */ | ||
| 36 | |||
| 37 | TWSR = 0; /* no prescaler */ | ||
| 38 | TWBR = 10; /* must be >= 10 for stable operation */ | ||
| 39 | |||
| 40 | }/* i2c_init */ | ||
| 41 | |||
| 42 | |||
| 43 | /************************************************************************* | ||
| 44 | Issues a start condition and sends address and transfer direction. | ||
| 45 | return 0 = device accessible, 1= failed to access device | ||
| 46 | *************************************************************************/ | ||
| 47 | unsigned char i2c_start(unsigned char address) | ||
| 48 | { | ||
| 49 | uint8_t twst; | ||
| 50 | |||
| 51 | // send START condition | ||
| 52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
| 53 | |||
| 54 | // wait until transmission completed | ||
| 55 | while(!(TWCR & (1<<TWINT))); | ||
| 56 | |||
| 57 | // check value of TWI Status Register. Mask prescaler bits. | ||
| 58 | twst = TW_STATUS & 0xF8; | ||
| 59 | if ( (twst != TW_START) && (twst != TW_REP_START)) return 1; | ||
| 60 | |||
| 61 | // send device address | ||
| 62 | TWDR = address; | ||
| 63 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 64 | |||
| 65 | // wail until transmission completed and ACK/NACK has been received | ||
| 66 | while(!(TWCR & (1<<TWINT))); | ||
| 67 | |||
| 68 | // check value of TWI Status Register. Mask prescaler bits. | ||
| 69 | twst = TW_STATUS & 0xF8; | ||
| 70 | if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return 1; | ||
| 71 | |||
| 72 | return 0; | ||
| 73 | |||
| 74 | }/* i2c_start */ | ||
| 75 | |||
| 76 | |||
| 77 | /************************************************************************* | ||
| 78 | Issues a start condition and sends address and transfer direction. | ||
| 79 | If device is busy, use ack polling to wait until device is ready | ||
| 80 | |||
| 81 | Input: address and transfer direction of I2C device | ||
| 82 | *************************************************************************/ | ||
| 83 | void i2c_start_wait(unsigned char address) | ||
| 84 | { | ||
| 85 | uint8_t twst; | ||
| 86 | |||
| 87 | |||
| 88 | while ( 1 ) | ||
| 89 | { | ||
| 90 | // send START condition | ||
| 91 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
| 92 | |||
| 93 | // wait until transmission completed | ||
| 94 | while(!(TWCR & (1<<TWINT))); | ||
| 95 | |||
| 96 | // check value of TWI Status Register. Mask prescaler bits. | ||
| 97 | twst = TW_STATUS & 0xF8; | ||
| 98 | if ( (twst != TW_START) && (twst != TW_REP_START)) continue; | ||
| 99 | |||
| 100 | // send device address | ||
| 101 | TWDR = address; | ||
| 102 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 103 | |||
| 104 | // wail until transmission completed | ||
| 105 | while(!(TWCR & (1<<TWINT))); | ||
| 106 | |||
| 107 | // check value of TWI Status Register. Mask prescaler bits. | ||
| 108 | twst = TW_STATUS & 0xF8; | ||
| 109 | if ( (twst == TW_MT_SLA_NACK )||(twst ==TW_MR_DATA_NACK) ) | ||
| 110 | { | ||
| 111 | /* device busy, send stop condition to terminate write operation */ | ||
| 112 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
| 113 | |||
| 114 | // wait until stop condition is executed and bus released | ||
| 115 | while(TWCR & (1<<TWSTO)); | ||
| 116 | |||
| 117 | continue; | ||
| 118 | } | ||
| 119 | //if( twst != TW_MT_SLA_ACK) return 1; | ||
| 120 | break; | ||
| 121 | } | ||
| 122 | |||
| 123 | }/* i2c_start_wait */ | ||
| 124 | |||
| 125 | |||
| 126 | /************************************************************************* | ||
| 127 | Issues a repeated start condition and sends address and transfer direction | ||
| 128 | |||
| 129 | Input: address and transfer direction of I2C device | ||
| 130 | |||
| 131 | Return: 0 device accessible | ||
| 132 | 1 failed to access device | ||
| 133 | *************************************************************************/ | ||
| 134 | unsigned char i2c_rep_start(unsigned char address) | ||
| 135 | { | ||
| 136 | return i2c_start( address ); | ||
| 137 | |||
| 138 | }/* i2c_rep_start */ | ||
| 139 | |||
| 140 | |||
| 141 | /************************************************************************* | ||
| 142 | Terminates the data transfer and releases the I2C bus | ||
| 143 | *************************************************************************/ | ||
| 144 | void i2c_stop(void) | ||
| 145 | { | ||
| 146 | /* send stop condition */ | ||
| 147 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
| 148 | |||
| 149 | // wait until stop condition is executed and bus released | ||
| 150 | while(TWCR & (1<<TWSTO)); | ||
| 151 | |||
| 152 | }/* i2c_stop */ | ||
| 153 | |||
| 154 | |||
| 155 | /************************************************************************* | ||
| 156 | Send one byte to I2C device | ||
| 157 | |||
| 158 | Input: byte to be transfered | ||
| 159 | Return: 0 write successful | ||
| 160 | 1 write failed | ||
| 161 | *************************************************************************/ | ||
| 162 | unsigned char i2c_write( unsigned char data ) | ||
| 163 | { | ||
| 164 | uint8_t twst; | ||
| 165 | |||
| 166 | // send data to the previously addressed device | ||
| 167 | TWDR = data; | ||
| 168 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 169 | |||
| 170 | // wait until transmission completed | ||
| 171 | while(!(TWCR & (1<<TWINT))); | ||
| 172 | |||
| 173 | // check value of TWI Status Register. Mask prescaler bits | ||
| 174 | twst = TW_STATUS & 0xF8; | ||
| 175 | if( twst != TW_MT_DATA_ACK) return 1; | ||
| 176 | return 0; | ||
| 177 | |||
| 178 | }/* i2c_write */ | ||
| 179 | |||
| 180 | |||
| 181 | /************************************************************************* | ||
| 182 | Read one byte from the I2C device, request more data from device | ||
| 183 | |||
| 184 | Return: byte read from I2C device | ||
| 185 | *************************************************************************/ | ||
| 186 | unsigned char i2c_readAck(void) | ||
| 187 | { | ||
| 188 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA); | ||
| 189 | while(!(TWCR & (1<<TWINT))); | ||
| 190 | |||
| 191 | return TWDR; | ||
| 192 | |||
| 193 | }/* i2c_readAck */ | ||
| 194 | |||
| 195 | |||
| 196 | /************************************************************************* | ||
| 197 | Read one byte from the I2C device, read is followed by a stop condition | ||
| 198 | |||
| 199 | Return: byte read from I2C device | ||
| 200 | *************************************************************************/ | ||
| 201 | unsigned char i2c_readNak(void) | ||
| 202 | { | ||
| 203 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 204 | while(!(TWCR & (1<<TWINT))); | ||
| 205 | |||
| 206 | return TWDR; | ||
| 207 | |||
| 208 | }/* i2c_readNak */ | ||
