summaryrefslogtreecommitdiff
path: root/keyboards/panc60
diff options
context:
space:
mode:
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-04-06 18:08:57 -0700
committerDrashna Jaelre <drashna@live.com>2019-04-06 18:08:57 -0700
commit5c1ef2bddc0fa5d4753d33a5ec8fed5d9da736c8 (patch)
tree4bb67d40c1bb3d90204977d4d47306859fb2ec2a /keyboards/panc60
parent410984486b0a5c61174c6e4e5a3570f1b09f97dc (diff)
[Keyboard] Panc60 Refactor (#5559)
* remove unneeded uart setting * use pragma once everywhere * remove custom matrix support * fixup readme * set bootmagic to lite * remove dependency on custom i2c code * use the right header files and function calls
Diffstat (limited to 'keyboards/panc60')
-rw-r--r--keyboards/panc60/config.h2
-rw-r--r--keyboards/panc60/i2c.c106
-rw-r--r--keyboards/panc60/i2c.h27
-rw-r--r--keyboards/panc60/matrix.c145
-rw-r--r--keyboards/panc60/panc60.c4
-rw-r--r--keyboards/panc60/panc60.h5
-rw-r--r--keyboards/panc60/readme.md8
-rw-r--r--keyboards/panc60/rules.mk5
-rw-r--r--keyboards/panc60/usbconfig.h5
9 files changed, 11 insertions, 296 deletions
diff --git a/keyboards/panc60/config.h b/keyboards/panc60/config.h
index 00bdbc60f1..edb25ad274 100644
--- a/keyboards/panc60/config.h
+++ b/keyboards/panc60/config.h
@@ -39,5 +39,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
39#define NO_BACKLIGHT_CLOCK 39#define NO_BACKLIGHT_CLOCK
40#define BACKLIGHT_LEVELS 1 40#define BACKLIGHT_LEVELS 1
41#define RGBLIGHT_ANIMATIONS 41#define RGBLIGHT_ANIMATIONS
42
43#define NO_UART 1
diff --git a/keyboards/panc60/i2c.c b/keyboards/panc60/i2c.c
deleted file mode 100644
index e8c4455ad1..0000000000
--- a/keyboards/panc60/i2c.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/*
2Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18// Please do not modify this file
19
20#include <avr/io.h>
21#include <util/twi.h>
22
23#include "i2c.h"
24
25void i2c_set_bitrate(uint16_t bitrate_khz) {
26 uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
27 if (bitrate_div >= 16) {
28 bitrate_div = (bitrate_div - 16) / 2;
29 }
30 TWBR = bitrate_div;
31}
32
33void i2c_init(void) {
34 // set pull-up resistors on I2C bus pins
35 PORTC |= 0b11;
36
37 i2c_set_bitrate(400);
38
39 // enable TWI (two-wire interface)
40 TWCR |= (1 << TWEN);
41
42 // enable TWI interrupt and slave address ACK
43 TWCR |= (1 << TWIE);
44 TWCR |= (1 << TWEA);
45}
46
47uint8_t i2c_start(uint8_t address) {
48 // reset TWI control register
49 TWCR = 0;
50
51 // begin transmission and wait for it to end
52 TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
53 while (!(TWCR & (1<<TWINT)));
54
55 // check if the start condition was successfully transmitted
56 if ((TWSR & 0xF8) != TW_START) {
57 return 1;
58 }
59
60 // transmit address and wait
61 TWDR = address;
62 TWCR = (1<<TWINT) | (1<<TWEN);
63 while (!(TWCR & (1<<TWINT)));
64
65 // check if the device has acknowledged the READ / WRITE mode
66 uint8_t twst = TW_STATUS & 0xF8;
67 if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
68 return 1;
69 }
70
71 return 0;
72}
73
74void i2c_stop(void) {
75 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
76}
77
78uint8_t i2c_write(uint8_t data) {
79 TWDR = data;
80
81 // transmit data and wait
82 TWCR = (1<<TWINT) | (1<<TWEN);
83 while (!(TWCR & (1<<TWINT)));
84
85 if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
86 return 1;
87 }
88
89 return 0;
90}
91
92uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
93 if (i2c_start(address)) {
94 return 1;
95 }
96
97 for (uint16_t i = 0; i < length; i++) {
98 if (i2c_write(data[i])) {
99 return 1;
100 }
101 }
102
103 i2c_stop();
104
105 return 0;
106}
diff --git a/keyboards/panc60/i2c.h b/keyboards/panc60/i2c.h
deleted file mode 100644
index 7ce50cdb57..0000000000
--- a/keyboards/panc60/i2c.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/*
2Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18// Please do not modify this file
19
20#ifndef __I2C_H__
21#define __I2C_H__
22
23void i2c_init(void);
24void i2c_set_bitrate(uint16_t bitrate_khz);
25uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
26
27#endif
diff --git a/keyboards/panc60/matrix.c b/keyboards/panc60/matrix.c
deleted file mode 100644
index cf0f63837b..0000000000
--- a/keyboards/panc60/matrix.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2Copyright 2018 Jack Humbert <jack.humb@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <avr/io.h>
19#include <util/delay.h>
20#include <string.h>
21#include "matrix.h"
22
23#ifndef DEBOUNCE
24# define DEBOUNCE 5
25#endif
26
27__attribute__ ((weak))
28void matrix_init_kb(void) {
29 matrix_init_user();
30}
31
32__attribute__ ((weak))
33void matrix_scan_kb(void) {
34 matrix_scan_user();
35}
36
37__attribute__ ((weak))
38void matrix_init_user(void) { }
39
40__attribute__ ((weak))
41void matrix_scan_user(void) { }
42
43// #define MATRIX_ROW_PINS { B3, B4, B5, B6, B7 }
44// #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
45
46static uint8_t debouncing = DEBOUNCE;
47
48static matrix_row_t matrix[MATRIX_ROWS];
49static matrix_row_t matrix_debouncing[MATRIX_ROWS];
50
51void matrix_init(void) {
52
53 // disables JTAG so we can use them as columns
54 MCUCSR = (1<<JTD);
55 MCUCSR = (1<<JTD);
56
57 // rows (output)
58 DDRB |= ((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7));
59 PORTB |= ((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7));
60
61 // cols (input)
62 DDRA &= ~((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7));
63 DDRC &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2));
64 DDRD &= ~((1 << 7));
65
66 // pull-up cols
67 PORTA |= ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7));
68 PORTC |= ((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2));
69 PORTD |= ((1 << 7));
70
71 // initialize matrix state: all keys off
72 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
73 matrix[row] = 0x00;
74 matrix_debouncing[row] = 0x00;
75 }
76
77 matrix_init_quantum();
78}
79
80uint8_t matrix_scan(void) {
81
82 // actual matrix scan
83 for (uint8_t c = 0; c < MATRIX_ROWS; c++) {
84 switch (c) {
85 case 0: PORTB &= ~(1 << 3); break;
86 case 1: PORTB &= ~(1 << 4); break;
87 case 2: PORTB &= ~(1 << 5); break;
88 case 3: PORTB &= ~(1 << 6); break;
89 case 4: PORTB &= ~(1 << 7); break;
90 }
91 _delay_us(5);
92
93 matrix_row_t current_row = (
94 (((PINA & (1 << 0)) ? 0 : 1 ) << 0) |
95 (((PINA & (1 << 1)) ? 0 : 1 ) << 1) |
96 (((PINA & (1 << 2)) ? 0 : 1 ) << 2) |
97 (((PINA & (1 << 3)) ? 0 : 1 ) << 3) |
98 (((PINA & (1 << 4)) ? 0 : 1 ) << 4) |
99 (((PINA & (1 << 5)) ? 0 : 1 ) << 5) |
100 (((PINA & (1 << 6)) ? 0 : 1 ) << 6) |
101 (((PINA & (1 << 7)) ? 0 : 1 ) << 7) |
102 (((PINC & (1 << 7)) ? 0 : 1 ) << 8) |
103 (((PINC & (1 << 6)) ? 0 : 1 ) << 9) |
104 (((PINC & (1 << 5)) ? 0 : 1 ) << 10) |
105 (((PINC & (1 << 4)) ? 0 : 1 ) << 11) |
106 (((PINC & (1 << 3)) ? 0 : 1 ) << 12) |
107 (((PINC & (1 << 2)) ? 0 : 1 ) << 13) |
108 (((PIND & (1 << 7)) ? 0 : 1 ) << 14)
109 );
110
111 switch (c) {
112 case 0: PORTB |= (1 << 3); break;
113 case 1: PORTB |= (1 << 4); break;
114 case 2: PORTB |= (1 << 5); break;
115 case 3: PORTB |= (1 << 6); break;
116 case 4: PORTB |= (1 << 7); break;
117 }
118
119 if (matrix_debouncing[c] != current_row) {
120 matrix_debouncing[c] = current_row;
121 debouncing = DEBOUNCE;
122 }
123 }
124
125 if (debouncing) {
126 if (--debouncing) {
127 _delay_ms(1);
128 } else {
129 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
130 matrix[i] = matrix_debouncing[i];
131 }
132 }
133 }
134
135 matrix_scan_quantum();
136
137 return 1;
138}
139
140inline matrix_row_t matrix_get_row(uint8_t row) {
141 return matrix[row];
142}
143
144void matrix_print(void) {
145}
diff --git a/keyboards/panc60/panc60.c b/keyboards/panc60/panc60.c
index 9ac087dbf2..16674d30d2 100644
--- a/keyboards/panc60/panc60.c
+++ b/keyboards/panc60/panc60.c
@@ -24,7 +24,7 @@
24#include <avr/pgmspace.h> 24#include <avr/pgmspace.h>
25 25
26#include "action_layer.h" 26#include "action_layer.h"
27#include "i2c.h" 27#include "i2c_master.h"
28#include "quantum.h" 28#include "quantum.h"
29 29
30__attribute__ ((weak)) 30__attribute__ ((weak))
@@ -44,7 +44,7 @@ void rgblight_set(void) {
44 } 44 }
45 45
46 i2c_init(); 46 i2c_init();
47 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); 47 i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
48} 48}
49#endif 49#endif
50 50
diff --git a/keyboards/panc60/panc60.h b/keyboards/panc60/panc60.h
index 95dcb1f90b..ee4569c615 100644
--- a/keyboards/panc60/panc60.h
+++ b/keyboards/panc60/panc60.h
@@ -13,8 +13,7 @@
13 * You should have received a copy of the GNU General Public License 13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16#ifndef PANC60_H 16#pragma once
17#define PANC60_H
18 17
19#include "quantum.h" 18#include "quantum.h"
20 19
@@ -67,5 +66,3 @@
67 { K30, KC_NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, KC_NO, K3D, K3E }, \ 66 { K30, KC_NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, KC_NO, K3D, K3E }, \
68 { KC_NO, K41, K42, KC_NO, KC_NO, KC_NO, KC_NO, K47, KC_NO, KC_NO, K4A, KC_NO, K4C, KC_NO, KC_NO } \ 67 { KC_NO, K41, K42, KC_NO, KC_NO, KC_NO, KC_NO, K47, KC_NO, KC_NO, K4A, KC_NO, K4C, KC_NO, KC_NO } \
69} 68}
70
71#endif
diff --git a/keyboards/panc60/readme.md b/keyboards/panc60/readme.md
index 05ac3d72be..737f238f6c 100644
--- a/keyboards/panc60/readme.md
+++ b/keyboards/panc60/readme.md
@@ -14,6 +14,8 @@ Make example for this keyboard (after setting up your build environment):
14 14
15Flashing 15Flashing
16 16
17**Reset Key:** Hold down the key located at `K40`, commonly programmed as left control while plugging in the keyboard. You may also hold down the key located at `K00`, commonly programmed as the `Esc` key.
18
17ps2avr(GB) boards use an atmega32a microcontroller and a different bootloader. It is not flashable using the regular QMK methods. 19ps2avr(GB) boards use an atmega32a microcontroller and a different bootloader. It is not flashable using the regular QMK methods.
18 20
19To put the panc60 into reset, hold left control while plugging in. 21To put the panc60 into reset, hold left control while plugging in.
@@ -36,9 +38,9 @@ macOS:
36 ``` 38 ```
373. Install the following packages: 393. Install the following packages:
38 ``` 40 ```
39 brew install python 41 brew install python3
40 brew install pyusb 42 pip3 install pyusb
41 brew install --HEAD`https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb 43 brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb
42 44
434. Place your keyboard into reset. 454. Place your keyboard into reset.
445. Flash the board by typing `bootloadHID -r` followed by the path to your `.hex` file. 465. Flash the board by typing `bootloadHID -r` followed by the path to your `.hex` file.
diff --git a/keyboards/panc60/rules.mk b/keyboards/panc60/rules.mk
index 588562a95b..8438751822 100644
--- a/keyboards/panc60/rules.mk
+++ b/keyboards/panc60/rules.mk
@@ -31,7 +31,7 @@ F_CPU = 12000000
31BOOTLOADER = bootloadHID 31BOOTLOADER = bootloadHID
32 32
33# build options 33# build options
34BOOTMAGIC_ENABLE = yes 34BOOTMAGIC_ENABLE = lite
35MOUSEKEY_ENABLE = yes 35MOUSEKEY_ENABLE = yes
36EXTRAKEY_ENABLE = yes 36EXTRAKEY_ENABLE = yes
37CONSOLE_ENABLE = yes 37CONSOLE_ENABLE = yes
@@ -43,8 +43,7 @@ RGBLIGHT_CUSTOM_DRIVER = yes
43OPT_DEFS = -DDEBUG_LEVEL=0 43OPT_DEFS = -DDEBUG_LEVEL=0
44 44
45# custom matrix setup 45# custom matrix setup
46CUSTOM_MATRIX = yes 46SRC = i2c_master.c
47SRC = matrix.c i2c.c
48 47
49# programming options 48# programming options
50PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex 49PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex
diff --git a/keyboards/panc60/usbconfig.h b/keyboards/panc60/usbconfig.h
index d2d848fcdc..54a7d20f14 100644
--- a/keyboards/panc60/usbconfig.h
+++ b/keyboards/panc60/usbconfig.h
@@ -8,8 +8,7 @@
8 * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ 8 * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $
9 */ 9 */
10 10
11#ifndef __usbconfig_h_included__ 11#pragma once
12#define __usbconfig_h_included__
13 12
14#include "config.h" 13#include "config.h"
15 14
@@ -392,5 +391,3 @@ section at the end of this file).
392/* #define USB_INTR_PENDING EIFR */ 391/* #define USB_INTR_PENDING EIFR */
393#define USB_INTR_PENDING_BIT INTF1 392#define USB_INTR_PENDING_BIT INTF1
394#define USB_INTR_VECTOR INT1_vect 393#define USB_INTR_VECTOR INT1_vect
395
396#endif /* __usbconfig_h_included__ */