forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support both AVR and ps2avrGB targets for new_project script (qmk#2811)
* Stopping point at creating targets for new_project script * Add second argument for target * Add the ps2avrgb target * consider the case where the firmware type target is not valid * fix template files to be more generic * Code cleanup * Change variable name to be more descriptive * make avr the default * forgot to put the template files in * Take out useless comments * add usage info
- Loading branch information
1 parent
eabd258
commit 12db5d1
Showing
18 changed files
with
812 additions
and
5 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef CONFIG_H | ||
#define CONFIG_H | ||
|
||
#include "config_common.h" | ||
|
||
#define VENDOR_ID 0x20A0 | ||
#define PRODUCT_ID 0x422D | ||
#define MANUFACTURER You | ||
#define PRODUCT %KEYBOARD% | ||
|
||
#define RGBLED_NUM 16 | ||
|
||
#define MATRIX_ROWS 2 | ||
#define MATRIX_COLS 3 | ||
|
||
#define MATRIX_ROW_PINS { D0, D5 } | ||
#define MATRIX_COL_PINS { F1, F0, B0 } | ||
#define UNUSED_PINS | ||
|
||
#define DIODE_DIRECTION COL2ROW | ||
#define DEBOUNCING_DELAY 5 | ||
|
||
#define NO_BACKLIGHT_CLOCK | ||
#define BACKLIGHT_LEVELS 1 | ||
#define RGBLIGHT_ANIMATIONS | ||
|
||
#define NO_UART 1 | ||
|
||
/* key combination for command */ | ||
#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Please do not modify this file | ||
|
||
#include <avr/io.h> | ||
#include <util/twi.h> | ||
|
||
#include "i2c.h" | ||
|
||
void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
if (bitrate_div >= 16) { | ||
bitrate_div = (bitrate_div - 16) / 2; | ||
} | ||
TWBR = bitrate_div; | ||
} | ||
|
||
void i2c_init(void) { | ||
// set pull-up resistors on I2C bus pins | ||
PORTC |= 0b11; | ||
|
||
i2c_set_bitrate(400); | ||
|
||
// enable TWI (two-wire interface) | ||
TWCR |= (1 << TWEN); | ||
|
||
// enable TWI interrupt and slave address ACK | ||
TWCR |= (1 << TWIE); | ||
TWCR |= (1 << TWEA); | ||
} | ||
|
||
uint8_t i2c_start(uint8_t address) { | ||
// reset TWI control register | ||
TWCR = 0; | ||
|
||
// begin transmission and wait for it to end | ||
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
while (!(TWCR & (1<<TWINT))); | ||
|
||
// check if the start condition was successfully transmitted | ||
if ((TWSR & 0xF8) != TW_START) { | ||
return 1; | ||
} | ||
|
||
// transmit address and wait | ||
TWDR = address; | ||
TWCR = (1<<TWINT) | (1<<TWEN); | ||
while (!(TWCR & (1<<TWINT))); | ||
|
||
// check if the device has acknowledged the READ / WRITE mode | ||
uint8_t twst = TW_STATUS & 0xF8; | ||
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void i2c_stop(void) { | ||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
} | ||
|
||
uint8_t i2c_write(uint8_t data) { | ||
TWDR = data; | ||
|
||
// transmit data and wait | ||
TWCR = (1<<TWINT) | (1<<TWEN); | ||
while (!(TWCR & (1<<TWINT))); | ||
|
||
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
if (i2c_start(address)) { | ||
return 1; | ||
} | ||
|
||
for (uint16_t i = 0; i < length; i++) { | ||
if (i2c_write(data[i])) { | ||
return 1; | ||
} | ||
} | ||
|
||
i2c_stop(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// Please do not modify this file | ||
|
||
#ifndef __I2C_H__ | ||
#define __I2C_H__ | ||
|
||
void i2c_init(void); | ||
void i2c_set_bitrate(uint16_t bitrate_khz); | ||
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <avr/io.h> | ||
#include <util/delay.h> | ||
|
||
#include "matrix.h" | ||
|
||
#ifndef DEBOUNCE | ||
#define DEBOUNCE 5 | ||
#endif | ||
|
||
static uint8_t debouncing = DEBOUNCE; | ||
|
||
static matrix_row_t matrix[MATRIX_ROWS]; | ||
static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
|
||
void matrix_init(void) { | ||
// all outputs for rows high | ||
DDRB = 0xFF; | ||
PORTB = 0xFF; | ||
// all inputs for columns | ||
DDRA = 0x00; | ||
DDRC &= ~(0x111111<<2); | ||
DDRD &= ~(1<<PIND7); | ||
// all columns are pulled-up | ||
PORTA = 0xFF; | ||
PORTC |= (0b111111<<2); | ||
PORTD |= (1<<PIND7); | ||
|
||
// initialize matrix state: all keys off | ||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
matrix[row] = 0x00; | ||
matrix_debouncing[row] = 0x00; | ||
} | ||
} | ||
|
||
void matrix_set_row_status(uint8_t row) { | ||
DDRB = (1 << row); | ||
PORTB = ~(1 << row); | ||
} | ||
|
||
uint8_t bit_reverse(uint8_t x) { | ||
x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); | ||
x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); | ||
x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); | ||
return x; | ||
} | ||
|
||
uint8_t matrix_scan(void) { | ||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
matrix_set_row_status(row); | ||
_delay_us(5); | ||
|
||
matrix_row_t cols = ( | ||
// cols 0..7, PORTA 0 -> 7 | ||
(~PINA) & 0xFF | ||
) | ( | ||
// cols 8..13, PORTC 7 -> 0 | ||
bit_reverse((~PINC) & 0xFF) << 8 | ||
) | ( | ||
// col 14, PORTD 7 | ||
((~PIND) & (1 << PIND7)) << 7 | ||
); | ||
|
||
if (matrix_debouncing[row] != cols) { | ||
matrix_debouncing[row] = cols; | ||
debouncing = DEBOUNCE; | ||
} | ||
} | ||
|
||
if (debouncing) { | ||
if (--debouncing) { | ||
_delay_ms(1); | ||
} else { | ||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
matrix[i] = matrix_debouncing[i]; | ||
} | ||
} | ||
} | ||
|
||
matrix_scan_user(); | ||
|
||
return 1; | ||
} | ||
|
||
inline matrix_row_t matrix_get_row(uint8_t row) { | ||
return matrix[row]; | ||
} | ||
|
||
void matrix_print(void) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
# | ||
# 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 | ||
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# MCU name | ||
MCU = atmega32a | ||
PROTOCOL = VUSB | ||
|
||
# unsupported features for now | ||
NO_UART = yes | ||
NO_SUSPEND_POWER_DOWN = yes | ||
|
||
# processor frequency | ||
F_CPU = 12000000 | ||
|
||
# Bootloader | ||
# This definition is optional, and if your keyboard supports multiple bootloaders of | ||
# different sizes, comment this out, and the correct address will be loaded | ||
# automatically (+60). See bootloader.mk for all options. | ||
BOOTLOADER = bootloadHID | ||
|
||
# build options | ||
BOOTMAGIC_ENABLE = yes | ||
MOUSEKEY_ENABLE = yes | ||
EXTRAKEY_ENABLE = yes | ||
CONSOLE_ENABLE = yes | ||
COMMAND_ENABLE = yes | ||
BACKLIGHT_ENABLE = no | ||
RGBLIGHT_ENABLE = no | ||
RGBLIGHT_CUSTOM_DRIVER = yes | ||
|
||
OPT_DEFS = -DDEBUG_LEVEL=0 | ||
|
||
# custom matrix setup | ||
CUSTOM_MATRIX = yes | ||
SRC = matrix.c i2c.c | ||
|
||
# programming options | ||
PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Copyright 2017 REPLACE_WITH_YOUR_NAME | ||
* | ||
* 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 | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include "%KEYBOARD%.h" | ||
|
||
#include <avr/pgmspace.h> | ||
#include "action_layer.h" | ||
#include "i2c.h" | ||
#include "quantum.h" | ||
|
||
__attribute__ ((weak)) | ||
void matrix_scan_user(void) { | ||
} |
Oops, something went wrong.