From c7583d181a2cae24af60efa93caa3d662e5d48f4 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 22 Apr 2019 08:25:21 -0700 Subject: [PATCH] Update handwired/frenchdev keyboard (#5443) --- keyboards/handwired/frenchdev/config.h | 5 +- keyboards/handwired/frenchdev/frenchdev.c | 54 +++-- keyboards/handwired/frenchdev/frenchdev.h | 8 +- keyboards/handwired/frenchdev/i2cmaster.h | 178 --------------- .../frenchdev/keymaps/default/keymap.c | 152 +++++-------- keyboards/handwired/frenchdev/matrix.c | 29 +-- keyboards/handwired/frenchdev/rules.mk | 6 +- keyboards/handwired/frenchdev/twimaster.c | 208 ------------------ 8 files changed, 115 insertions(+), 525 deletions(-) delete mode 100644 keyboards/handwired/frenchdev/i2cmaster.h delete mode 100644 keyboards/handwired/frenchdev/twimaster.c diff --git a/keyboards/handwired/frenchdev/config.h b/keyboards/handwired/frenchdev/config.h index b01eec7aa0..eca6690905 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 along with this program. If not, see . */ -#ifndef FRENCHDEV_V1_CONFIG_H -#define FRENCHDEV_V1_CONFIG_H +#pragma once #include "config_common.h" @@ -81,5 +80,3 @@ along with this program. If not, see . //#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION //#define DEBUG_MATRIX_SCAN_RATE - -#endif //FRENCHDEV_V1_CONFIG_H diff --git a/keyboards/handwired/frenchdev/frenchdev.c b/keyboards/handwired/frenchdev/frenchdev.c index 6d5883a3a8..6eed4de5ff 100644 --- a/keyboards/handwired/frenchdev/frenchdev.c +++ b/keyboards/handwired/frenchdev/frenchdev.c @@ -1,5 +1,26 @@ #include "frenchdev.h" -#include "i2cmaster.h" + +extern inline void frenchdev_board_led_on(void); +extern inline void frenchdev_led_1_on(void); +extern inline void frenchdev_led_2_on(void); +extern inline void frenchdev_led_3_on(void); +extern inline void frenchdev_led_on(uint8_t led); + +extern inline void frenchdev_board_led_off(void); +extern inline void frenchdev_led_1_off(void); +extern inline void frenchdev_led_2_off(void); +extern inline void frenchdev_led_3_off(void); +extern inline void frenchdev_led_off(uint8_t led); + +extern inline void frenchdev_led_all_on(void); +extern inline void frenchdev_led_all_off(void); + +extern inline void frenchdev_led_1_set(uint8_t n); +extern inline void frenchdev_led_2_set(uint8_t n); +extern inline void frenchdev_led_3_set(uint8_t n); +extern inline void frenchdev_led_set(uint8_t led, uint8_t n); + +extern inline void frenchdev_led_all_set(uint8_t n); bool i2c_initialized = 0; uint8_t mcp23018_status = 0x20; @@ -31,15 +52,15 @@ void frenchdev_blink_all_leds(void) frenchdev_led_all_off(); frenchdev_led_all_set(LED_BRIGHTNESS_HI); frenchdev_led_1_on(); - _delay_ms(50); + wait_ms(50); frenchdev_led_2_on(); - _delay_ms(50); + wait_ms(50); frenchdev_led_3_on(); - _delay_ms(50); + wait_ms(50); frenchdev_led_1_off(); - _delay_ms(50); + wait_ms(50); frenchdev_led_2_off(); - _delay_ms(50); + wait_ms(50); frenchdev_led_3_off(); frenchdev_led_all_off(); } @@ -54,28 +75,28 @@ uint8_t init_mcp23018(void) { // cli(); if (i2c_initialized == 0) { i2c_init(); // on pins D(1,0) - i2c_initialized++; - _delay_ms(1000); + i2c_initialized = true;; + wait_ms(1000); } // set pin direction // - unused : input : 1 // - input : input : 1 // - driving : output : 0 - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out; + mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(IODIRA, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00000000, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00111111, I2C_TIMEOUT); if (mcp23018_status) goto out; i2c_stop(); // set pull-up // - unused : on : 1 // - input : on : 1 // - driving : off : 0 - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out; + mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(GPPUA, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00000000, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00111111, I2C_TIMEOUT); if (mcp23018_status) goto out; out: i2c_stop(); @@ -84,4 +105,3 @@ out: return mcp23018_status; } - diff --git a/keyboards/handwired/frenchdev/frenchdev.h b/keyboards/handwired/frenchdev/frenchdev.h index 82dbe18b89..1df3990887 100644 --- a/keyboards/handwired/frenchdev/frenchdev.h +++ b/keyboards/handwired/frenchdev/frenchdev.h @@ -1,10 +1,9 @@ -#ifndef FRENCHDEV_V1_H -#define FRENCHDEV_V1_H +#pragma once #include "quantum.h" #include #include -#include "i2cmaster.h" +#include "i2c_master.h" #include #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) @@ -24,6 +23,7 @@ #define OLATB 0x15 extern uint8_t mcp23018_status; +#define I2C_TIMEOUT 100 void init_frenchdev(void); void frenchdev_blink_all_leds(void); @@ -111,5 +111,3 @@ inline void frenchdev_led_all_set(uint8_t n) { k51, k41, k31, k21, k11, k01 }, \ { k50, k40, k30, k20, k10, KC_NO } \ } - -#endif diff --git a/keyboards/handwired/frenchdev/i2cmaster.h b/keyboards/handwired/frenchdev/i2cmaster.h deleted file mode 100644 index 3917b9e6c0..0000000000 --- a/keyboards/handwired/frenchdev/i2cmaster.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef _I2CMASTER_H -#define _I2CMASTER_H 1 -/************************************************************************* -* Title: C include file for the I2C master interface -* (i2cmaster.S or twimaster.c) -* Author: Peter Fleury http://jump.to/fleury -* File: $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $ -* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 -* Target: any AVR device -* Usage: see Doxygen manual -**************************************************************************/ - -#ifdef DOXYGEN -/** - @defgroup pfleury_ic2master I2C Master library - @code #include @endcode - - @brief I2C (TWI) Master Software Library - - Basic routines for communicating with I2C slave devices. This single master - implementation is limited to one bus master on the I2C bus. - - This I2c library is implemented as a compact assembler software implementation of the I2C protocol - which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (twimaster.c). - Since the API for these two implementations is exactly the same, an application can be linked either against the - software I2C implementation or the hardware I2C implementation. - - Use 4.7k pull-up resistor on the SDA and SCL pin. - - Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module - i2cmaster.S to your target when using the software I2C implementation ! - - Adjust the CPU clock frequence F_CPU in twimaster.c or in the Makfile when using the TWI hardware implementaion. - - @note - The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted - to GNU assembler and AVR-GCC C call interface. - Replaced the incorrect quarter period delays found in AVR300 with - half period delays. - - @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury - - @par API Usage Example - The following code shows typical usage of this library, see example test_i2cmaster.c - - @code - - #include - - - #define Dev24C02 0xA2 // device address of EEPROM 24C02, see datasheet - - int main(void) - { - unsigned char ret; - - i2c_init(); // initialize I2C library - - // write 0x75 to EEPROM address 5 (Byte Write) - i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode - i2c_write(0x05); // write address = 5 - i2c_write(0x75); // write value 0x75 to EEPROM - i2c_stop(); // set stop conditon = release bus - - - // read previously written value back from EEPROM address 5 - i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode - - i2c_write(0x05); // write address = 5 - i2c_rep_start(Dev24C02+I2C_READ); // set device address and read mode - - ret = i2c_readNak(); // read one byte from EEPROM - i2c_stop(); - - for(;;); - } - @endcode - -*/ -#endif /* DOXYGEN */ - -/**@{*/ - -#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 -#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" -#endif - -#include - -/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */ -#define I2C_READ 1 - -/** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */ -#define I2C_WRITE 0 - - -/** - @brief initialize the I2C master interace. Need to be called only once - @param void - @return none - */ -extern void i2c_init(void); - - -/** - @brief Terminates the data transfer and releases the I2C bus - @param void - @return none - */ -extern void i2c_stop(void); - - -/** - @brief Issues a start condition and sends address and transfer direction - - @param addr address and transfer direction of I2C device - @retval 0 device accessible - @retval 1 failed to access device - */ -extern unsigned char i2c_start(unsigned char addr); - - -/** - @brief Issues a repeated start condition and sends address and transfer direction - - @param addr address and transfer direction of I2C device - @retval 0 device accessible - @retval 1 failed to access device - */ -extern unsigned char i2c_rep_start(unsigned char addr); - - -/** - @brief Issues a start condition and sends address and transfer direction - - If device is busy, use ack polling to wait until device ready - @param addr address and transfer direction of I2C device - @return none - */ -extern void i2c_start_wait(unsigned char addr); - - -/** - @brief Send one byte to I2C device - @param data byte to be transfered - @retval 0 write successful - @retval 1 write failed - */ -extern unsigned char i2c_write(unsigned char data); - - -/** - @brief read one byte from the I2C device, request more data from device - @return byte read from I2C device - */ -extern unsigned char i2c_readAck(void); - -/** - @brief read one byte from the I2C device, read is followed by a stop condition - @return byte read from I2C device - */ -extern unsigned char i2c_readNak(void); - -/** - @brief read one byte from the I2C device - - Implemented as a macro, which calls either i2c_readAck or i2c_readNak - - @param ack 1 send ack, request more data from device
- 0 send nak, read is followed by a stop condition - @return byte read from I2C device - */ -extern unsigned char i2c_read(unsigned char ack); -#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); - - -/**@}*/ -#endif diff --git a/keyboards/handwired/frenchdev/keymaps/default/keymap.c b/keyboards/handwired/frenchdev/keymaps/default/keymap.c index 506383a1bb..7b82f36e36 100644 --- a/keyboards/handwired/frenchdev/keymaps/default/keymap.c +++ b/keyboards/handwired/frenchdev/keymaps/default/keymap.c @@ -1,5 +1,4 @@ #include QMK_KEYBOARD_H -#include "mousekey.h" #include "keymap_bepo.h" @@ -14,7 +13,7 @@ #define KEY_DELAY 130 enum macros { - M_LP, // left pedal + M_LP = SAFE_RANGE, // left pedal M_RP, // right pedal M_SF, // shift M_SFS, // shift and space @@ -63,19 +62,18 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |------+------| / |------| , | space|------|------|------ .. ------|------|------| L1/sp| LEFT |------| UP |------+------| * * | CTRL | win |------/ \-------------| L1 | alt | .. | CAPS | L1 |-------------/ \------| : | CTRL | * * `-------------/ \-------------/ .. \-------------/ \-------------/ * - *M(M_LP) */ [_BASE] = LAYOUT( KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \ 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, \ 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, \ 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, \ - 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), \ - 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, \ + 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, \ + 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, \ //left pedals - M(M_LP), M(M_RP), KC_TRNS, \ + M_LP, M_RP, KC_TRNS, \ //right pedals - M(M_LP), M(M_RP), KC_TRNS \ + M_LP, M_RP, KC_TRNS \ ), /* Larer 1 for symbols. @@ -102,7 +100,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 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, \ 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, \ 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, \ - 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, \ + 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, \ 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, \ //left pedals KC_TRNS, KC_BTN1, KC_TRNS, \ @@ -134,12 +132,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 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, \ 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, \ 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, \ - 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, \ + 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, \ 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, \ //left pedals - KC_BTN3, M(M_RP), KC_TRNS, \ + KC_BTN3, M_RP, KC_TRNS, \ //right pedals - KC_BTN3, M(M_RP), KC_TRNS \ + KC_BTN3, M_RP, KC_TRNS \ ), /* TRNS - skeleton for laters @@ -169,9 +167,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 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, \ 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, \ //left pedals - KC_BTN3, M(M_RP), KC_TRNS, \ + KC_BTN3, M_RP, KC_TRNS, \ //right pedals - KC_BTN3, M(M_RP), KC_TRNS \ + KC_BTN3, M_RP, KC_TRNS \ ), }; @@ -191,28 +189,52 @@ void release_shift(void) { void press_space(void) { if(shift_count > 0) unregister_code (KC_LSHIFT); - register_code (KC_SPACE); - unregister_code (KC_SPACE); + tap_code(KC_SPACE); if(shift_count > 0) register_code (KC_LSHIFT); } void press_enter(void) { if(shift_count > 0) unregister_code (KC_LSHIFT); - register_code (KC_ENT); - unregister_code (KC_ENT); + tap_code (KC_ENT); if(shift_count > 0) register_code (KC_LSHIFT); } void press_underscore(void) { if(shift_count > 0) unregister_code (KC_LSHIFT); - register_code ((unsigned char) BP_UNDS); - unregister_code ((unsigned char) BP_UNDS); + tap_code ((unsigned char) BP_UNDS); if(shift_count > 0) register_code (KC_LSHIFT); } -const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) -{ - switch(id) { +void matrix_init_user(void) { +} + +// Bleah globals need to be initialized. +uint8_t old_layer=_BASE; + +void matrix_scan_user(void) { + uint8_t layer = biton32(layer_state); + + frenchdev_led_1_off(); + frenchdev_led_2_off(); + switch (layer) { + case _BASE: + frenchdev_led_2_on(); + break; + case _SYMBOLS: + frenchdev_led_1_on(); + break; + case _MEDIA: + frenchdev_led_1_on(); + frenchdev_led_2_on(); + default: + // none + break; + } +} + + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch(keycode) { case M_LP: //left pedal if (record->event.pressed) { layer_on(1); @@ -220,25 +242,19 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer. } else { if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) { - mousekey_on (KC_BTN2); - mousekey_send(); - mousekey_off (KC_BTN2); - mousekey_send(); + tap_code (KC_BTN2); } unregister_code (KC_SLCK); layer_off(1); } - break; + break; case M_RP: //right pedal if (record->event.pressed) { layer_on(2); key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer. } else { if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) { - mousekey_on (KC_BTN1); - mousekey_send(); - mousekey_off (KC_BTN1); - mousekey_send(); + tap_code (KC_BTN1); } layer_off(2); } @@ -289,13 +305,12 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) key_timer_2 = timer_read(); // if the key is being pressed, we start the timer. } else { if (timer_elapsed(key_timer_2) < KEY_DELAY) { - register_code (KC_INS); - unregister_code (KC_INS); + tap_code (KC_INS); } l2_locked = 0; layer_off(2); } - break; + break; case L2LOC: //lock L2 if (record->event.pressed) { 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) layer_off(2); } } - break; + break; case M_UN: // undo if (record->event.pressed) { - register_code(KC_LCTL); - register_code(BP_Z); - unregister_code(BP_Z); - unregister_code(KC_LCTL); + tap_code16(C(BP_Z)); } - break; + break; case M_CUT: // cut if (record->event.pressed) { - register_code(KC_LCTL); - register_code(BP_X); - unregister_code(BP_X); - unregister_code(KC_LCTL); + tap_code16(C(BP_X)); } - break; + break; case M_CP: // copy if (record->event.pressed) { - register_code(KC_LCTL); - register_code(BP_C); - unregister_code(BP_C); - unregister_code(KC_LCTL); + tap_code16(C(BP_C)); } - break; + break; case M_PS: // paste if (record->event.pressed) { - register_code(KC_LCTL); - register_code(BP_V); - unregister_code(BP_V); - unregister_code(KC_LCTL); + tap_code16(C(BP_V)); } - break; + break; case M_SE: // search if (record->event.pressed) { - register_code(KC_LCTL); - register_code(BP_F); - unregister_code(BP_F); - unregister_code(KC_LCTL); + tap_code16(C(BP_F)); } - break; + break; } - return MACRO_NONE; -}; - -void matrix_init_user(void) { -} - -// Bleah globals need to be initialized. -uint8_t old_layer=_BASE; - -void matrix_scan_user(void) { - uint8_t layer = biton32(layer_state); - - frenchdev_led_1_off(); - frenchdev_led_2_off(); - switch (layer) { - case _BASE: - frenchdev_led_2_on(); - break; - case _SYMBOLS: - frenchdev_led_1_on(); - break; - case _MEDIA: - frenchdev_led_1_on(); - frenchdev_led_2_on(); - default: - // none - break; - } -} - - -bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } diff --git a/keyboards/handwired/frenchdev/matrix.c b/keyboards/handwired/frenchdev/matrix.c index 7fe3d0bbf2..4263555e95 100644 --- a/keyboards/handwired/frenchdev/matrix.c +++ b/keyboards/handwired/frenchdev/matrix.c @@ -40,7 +40,6 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" #include "frenchdev.h" -#include "i2cmaster.h" #ifdef DEBUG_MATRIX_SCAN_RATE #include "timer.h" #endif @@ -280,11 +279,12 @@ static matrix_row_t read_cols(uint8_t row) return 0; } else { uint8_t data = 0; - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOB); if (mcp23018_status) goto out; - mcp23018_status = i2c_start(I2C_ADDR_READ); if (mcp23018_status) goto out; - data = i2c_readNak(); - data = ~data; + mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(GPIOB, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT); if (mcp23018_status) goto out; + data = i2c_read_nack(I2C_TIMEOUT); if (mcp23018_status < 0) goto out; + data = ~((uint8_t)mcp23018_status); + mcp23018_status = I2C_STATUS_SUCCESS; out: i2c_stop(); return data; @@ -318,11 +318,9 @@ static void unselect_rows(void) // do nothing } else { // set all rows hi-Z : 1 - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out; - mcp23018_status = i2c_write( 0xFF - & ~(0<<8) - ); if (mcp23018_status) goto out; + mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(GPIOA, I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write( 0xFF & ~(0<<8), I2C_TIMEOUT); if (mcp23018_status) goto out; out: i2c_stop(); } @@ -346,11 +344,9 @@ static void select_row(uint8_t row) } else { // set active row low : 0 // set other rows hi-Z : 1 - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out; - mcp23018_status = i2c_write( 0xFF & ~(1< http://jump.to/fleury -* File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ -* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 -* Target: any AVR device with hardware TWI -* Usage: API compatible with I2C Software Library i2cmaster.h -**************************************************************************/ -#include -#include - -#include - - -/* define CPU frequency in Mhz here if not defined in Makefile */ -#ifndef F_CPU -#define F_CPU 16000000UL -#endif - -/* I2C clock in Hz */ -#define SCL_CLOCK 400000L - - -/************************************************************************* - Initialization of the I2C bus interface. Need to be called only once -*************************************************************************/ -void i2c_init(void) -{ - /* initialize TWI clock - * minimal values in Bit Rate Register (TWBR) and minimal Prescaler - * bits in the TWI Status Register should give us maximal possible - * I2C bus speed - about 444 kHz - * - * for more details, see 20.5.2 in ATmega16/32 secification - */ - - TWSR = 0; /* no prescaler */ - TWBR = 10; /* must be >= 10 for stable operation */ - -}/* i2c_init */ - - -/************************************************************************* - Issues a start condition and sends address and transfer direction. - return 0 = device accessible, 1= failed to access device -*************************************************************************/ -unsigned char i2c_start(unsigned char address) -{ - uint8_t twst; - - // send START condition - TWCR = (1<