Compare commits

...

2 Commits

Author SHA1 Message Date
4f71243453 line endings 2017-08-02 23:57:02 -04:00
4e7ee5b0d5 start planning eeprom stuff 2017-08-01 16:45:33 -04:00
10 changed files with 998 additions and 904 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,31 @@
#ifndef I2C_H #ifndef I2C_H
#define I2C_H #define I2C_H
#include <stdint.h> #include <stdint.h>
#ifndef F_CPU #ifndef F_CPU
#define F_CPU 16000000UL #define F_CPU 16000000UL
#endif #endif
#define I2C_READ 1 #define I2C_READ 1
#define I2C_WRITE 0 #define I2C_WRITE 0
#define I2C_ACK 1 #define I2C_ACK 1
#define I2C_NACK 0 #define I2C_NACK 0
#define SLAVE_BUFFER_SIZE 0x10 #define SLAVE_BUFFER_SIZE 0x10
// i2c SCL clock frequency // i2c SCL clock frequency
#define SCL_CLOCK 100000L #define SCL_CLOCK 100000L
extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
void i2c_master_init(void); void i2c_master_init(void);
uint8_t i2c_master_start(uint8_t address); uint8_t i2c_master_start(uint8_t address);
void i2c_master_stop(void); void i2c_master_stop(void);
uint8_t i2c_master_write(uint8_t data); uint8_t i2c_master_write(uint8_t data);
uint8_t i2c_master_read(int); uint8_t i2c_master_read(int);
void i2c_reset_state(void); void i2c_reset_state(void);
void i2c_slave_init(uint8_t address); void i2c_slave_init(uint8_t address);
#endif #endif

View File

@ -1,31 +1,31 @@
/* /*
Copyright 2012 Jun Wako <wakojun@gmail.com> Copyright 2012 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define USE_SERIAL #define USE_SERIAL
#define MASTER_LEFT #define MASTER_LEFT
// #define _MASTER_RIGHT // #define _MASTER_RIGHT
// #define EE_HANDS // #define EE_HANDS
#ifdef SUBPROJECT_v2 #ifdef SUBPROJECT_v2
#include "../../v2/config.h" #include "../../v2/config.h"
#endif #endif
#ifdef SUBPROJECT_protosplit #ifdef SUBPROJECT_protosplit
#include "../../protosplit/config.h" #include "../../protosplit/config.h"
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,26 @@
#ifndef MY_SERIAL_H #ifndef MY_SERIAL_H
#define MY_SERIAL_H #define MY_SERIAL_H
#include "config.h" #include "config.h"
#include <stdbool.h> #include <stdbool.h>
/* TODO: some defines for interrupt setup */ /* TODO: some defines for interrupt setup */
#define SERIAL_PIN_DDR DDRD #define SERIAL_PIN_DDR DDRD
#define SERIAL_PIN_PORT PORTD #define SERIAL_PIN_PORT PORTD
#define SERIAL_PIN_INPUT PIND #define SERIAL_PIN_INPUT PIND
#define SERIAL_PIN_MASK _BV(PD0) #define SERIAL_PIN_MASK _BV(PD0)
#define SERIAL_PIN_INTERRUPT INT0_vect #define SERIAL_PIN_INTERRUPT INT0_vect
#define SERIAL_SLAVE_BUFFER_LENGTH ((MATRIX_COLS+7)/8 *MATRIX_ROWS/2) #define SERIAL_SLAVE_BUFFER_LENGTH ((MATRIX_COLS+7)/8 *MATRIX_ROWS/2)
#define SERIAL_MASTER_BUFFER_LENGTH 1 #define SERIAL_MASTER_BUFFER_LENGTH 1
// Buffers for master - slave communication // Buffers for master - slave communication
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH]; extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH]; extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
void serial_master_init(void); void serial_master_init(void);
void serial_slave_init(void); void serial_slave_init(void);
int serial_update_buffers(void); int serial_update_buffers(void);
bool serial_slave_data_corrupt(void); bool serial_slave_data_corrupt(void);
#endif #endif

View File

@ -1,81 +1,81 @@
#include <avr/io.h> #include <avr/io.h>
#include <avr/wdt.h> #include <avr/wdt.h>
#include <avr/power.h> #include <avr/power.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <util/delay.h> #include <util/delay.h>
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include "split_util.h" #include "split_util.h"
#include "matrix.h" #include "matrix.h"
#include "keyboard.h" #include "keyboard.h"
#include "config.h" #include "config.h"
#ifdef USE_I2C #ifdef USE_I2C
# include "i2c.h" # include "i2c.h"
#else #else
# include "serial.h" # include "serial.h"
#endif #endif
volatile bool isLeftHand = true; volatile bool isLeftHand = true;
static void setup_handedness(void) { static void setup_handedness(void) {
#ifdef EE_HANDS #ifdef EE_HANDS
isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
#else #else
// I2C_MASTER_RIGHT is deprecated use MASTER_RIGHT instead since this works for both serial and i2c // I2C_MASTER_RIGHT is deprecated use MASTER_RIGHT instead since this works for both serial and i2c
#if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
isLeftHand = !has_usb(); isLeftHand = !has_usb();
#else #else
isLeftHand = has_usb(); isLeftHand = has_usb();
#endif #endif
#endif #endif
} }
static void keyboard_master_setup(void) { static void keyboard_master_setup(void) {
#ifdef USE_I2C #ifdef USE_I2C
i2c_master_init(); i2c_master_init();
#else #else
serial_master_init(); serial_master_init();
#endif #endif
} }
static void keyboard_slave_setup(void) { static void keyboard_slave_setup(void) {
#ifdef USE_I2C #ifdef USE_I2C
i2c_slave_init(SLAVE_I2C_ADDRESS); i2c_slave_init(SLAVE_I2C_ADDRESS);
#else #else
serial_slave_init(); serial_slave_init();
#endif #endif
} }
bool has_usb(void) { bool has_usb(void) {
USBCON |= (1 << OTGPADE); //enables VBUS pad USBCON |= (1 << OTGPADE); //enables VBUS pad
_delay_us(5); _delay_us(5);
return (USBSTA & (1<<VBUS)); //checks state of VBUS return (USBSTA & (1<<VBUS)); //checks state of VBUS
} }
void split_keyboard_setup(void) { void split_keyboard_setup(void) {
setup_handedness(); setup_handedness();
if (has_usb()) { if (has_usb()) {
keyboard_master_setup(); keyboard_master_setup();
} else { } else {
keyboard_slave_setup(); keyboard_slave_setup();
} }
sei(); sei();
} }
void keyboard_slave_loop(void) { void keyboard_slave_loop(void) {
matrix_init(); matrix_init();
while (1) { while (1) {
matrix_slave_scan(); matrix_slave_scan();
} }
} }
// this code runs before the usb and keyboard is initialized // this code runs before the usb and keyboard is initialized
void matrix_setup(void) { void matrix_setup(void) {
split_keyboard_setup(); split_keyboard_setup();
if (!has_usb()) { if (!has_usb()) {
keyboard_slave_loop(); keyboard_slave_loop();
} }
} }

View File

@ -1,22 +1,22 @@
#ifndef SPLIT_KEYBOARD_UTIL_H #ifndef SPLIT_KEYBOARD_UTIL_H
#define SPLIT_KEYBOARD_UTIL_H #define SPLIT_KEYBOARD_UTIL_H
#include <stdbool.h> #include <stdbool.h>
#ifdef EE_HANDS #ifdef EE_HANDS
#define EECONFIG_BOOTMAGIC_END (uint8_t *)10 #define EECONFIG_BOOTMAGIC_END (uint8_t *)10
#define EECONFIG_HANDEDNESS EECONFIG_BOOTMAGIC_END #define EECONFIG_HANDEDNESS EECONFIG_BOOTMAGIC_END
#endif #endif
#define SLAVE_I2C_ADDRESS 0x32 #define SLAVE_I2C_ADDRESS 0x32
extern volatile bool isLeftHand; extern volatile bool isLeftHand;
// slave version of matix scan, defined in matrix.c // slave version of matix scan, defined in matrix.c
void matrix_slave_scan(void); void matrix_slave_scan(void);
void split_keyboard_setup(void); void split_keyboard_setup(void);
bool has_usb(void); bool has_usb(void);
void keyboard_slave_loop(void); void keyboard_slave_loop(void);
#endif #endif

View File

@ -5,7 +5,7 @@
void eeconfig_init(void) void eeconfig_init(void)
{ {
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); eeprom_update_word(EEPROM_SIGNATURE_ADDR, EEPROM_SIGNATURE);
eeprom_update_byte(EECONFIG_DEBUG, 0); eeprom_update_byte(EECONFIG_DEBUG, 0);
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
eeprom_update_byte(EECONFIG_KEYMAP, 0); eeprom_update_byte(EECONFIG_KEYMAP, 0);
@ -24,19 +24,59 @@ void eeconfig_init(void)
#endif #endif
} }
uint8_t eeprom_feature_location(eeprom_feature_t feature) {
uint8_t location = EEPROM_HEADER_SIZE;
if (feature == eeprom_debug)
return location;
location += sizeof(typeof(eeprom_debug));
if (feature == eeprom_default_layer)
return location;
location += sizeof(typeof(eeprom_default_layer));
if (feature == eeprom_keymap)
return location;
location += sizeof(typeof(eeprom_keymap));
if (feature == eeprom_mousekey_accel)
return location;
location += sizeof(typeof(eeprom_mousekey_accel));
#ifdef BACKLIGHT_ENABLE
if (feature == eeprom_backlight)
return location;
location += sizeof(typeof(eeprom_backlight));
#endif
#ifdef AUDIO_ENABLE
if (feature == eeprom_audio)
return location;
location += sizeof(typeof(eeprom_audio));
#endif
#ifdef RGBLIGHT_ENABLE
if (feature == eeprom_rgblight)
return location;
location += sizeof(typeof(eeprom_rgblight));
#endif
if (feature == eeprom_unicodemode)
return location;
location += sizeof(typeof(eeprom_unicodemode));
#ifdef STENO_ENABLE
if (feature == eeprom_stenomode)
return location;
location += sizeof(typeof(eeprom_stenomode));
#endif
return location;
}
void eeconfig_enable(void) void eeconfig_enable(void)
{ {
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); eeprom_update_word(EEPROM_SIGNATURE_ADDR, EEPROM_SIGNATURE);
} }
void eeconfig_disable(void) void eeconfig_disable(void)
{ {
eeprom_update_word(EECONFIG_MAGIC, 0xFFFF); eeprom_update_word(EEPROM_SIGNATURE_ADDR, 0xFFFF);
} }
bool eeconfig_is_enabled(void) bool eeconfig_is_enabled(void)
{ {
return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); return (eeprom_read_word(EEPROM_SIGNATURE_ADDR) == EEPROM_SIGNATURE);
} }
uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }

View File

@ -21,8 +21,62 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define EEPROM_CONFIG_VERSION 1
#define EEPROM_HEADER_SIZE 4
#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED #define EEPROM_SIGNATURE (0xFEED - EEPROM_CONFIG_VERSION)
#define EEPROM_SIGNATURE_ADDR (uint16_t *)0
#define EEPROM_ENABLED_FEATURES eeprom_enabled_features
#define EEPROM_ENABLED_FEATURES_ADDR (uint16_t *)2
enum eeprom_optional_features {
eeprom_backlight_option,
eeprom_audio_option,
eeprom_rgblight_option,
eeprom_stenomode_option,
eeprom_free_range_option
};
static const uint16_t eeprom_enabled_features =
#ifdef BACKLIGHT_ENABLE
(1 << eeprom_backlight_option) |
#endif
#ifdef AUDIO_ENABLE
(1 << eeprom_audio_option) |
#endif
#ifdef RGBLIGHT_ENABLE
(1 << eeprom_rgblight_option) |
#endif
#ifdef STENO_ENABLE
(1 << eeprom_stenomode_option) |
#endif
0;
typedef enum eeprom_features {
eeprom_debug,
eeprom_default_layer,
eeprom_keymap,
eeprom_mousekey_accel,
eeprom_backlight,
eeprom_audio,
eeprom_rgblight,
eeprom_unicodemode,
eeprom_stenomode,
eeprom_free_range
} eeprom_feature_t;
typedef uint8_t eeprom_debug_t;
typedef uint8_t eeprom_default_layer_t;
typedef uint8_t eeprom_keymap_t;
typedef uint8_t eeprom_mousekey_accel_t;
typedef uint8_t eeprom_backlight_t;
typedef uint8_t eeprom_audio_t;
typedef uint32_t eeprom_rgblight_t;
typedef uint8_t eeprom_unicodemode_t;
typedef uint8_t eeprom_stenomode_t;
#define typeof(n) n ## _t
/* eeprom parameteter address */ /* eeprom parameteter address */
#define EECONFIG_MAGIC (uint16_t *)0 #define EECONFIG_MAGIC (uint16_t *)0