aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-04-30 16:24:47 +1000
committerGitHub <noreply@github.com>2020-04-30 16:24:47 +1000
commit16a15c1cfcbfd0feb2c2cf1383676747e2f97d73 (patch)
treeaaa3c9f5a23207861d05c37ed4860af8efd40f85
parent37a4b53c4f51b66992e687b5012c83df9cc6b138 (diff)
downloadqmk_firmware-16a15c1cfcbfd0feb2c2cf1383676747e2f97d73.tar.gz
qmk_firmware-16a15c1cfcbfd0feb2c2cf1383676747e2f97d73.zip
QMK-ify some GPIO macros (#8315)
-rw-r--r--drivers/avr/apa102.c8
-rw-r--r--drivers/avr/ssd1306.h1
-rw-r--r--keyboards/40percentclub/nano/keymaps/drashna/keymap.c1
-rw-r--r--keyboards/claw44/ssd1306.h3
-rw-r--r--keyboards/comet46/ssd1306.h3
-rw-r--r--keyboards/converter/palm_usb/matrix.c41
-rw-r--r--keyboards/crkbd/ssd1306.h3
-rw-r--r--keyboards/helix/local_drivers/ssd1306.h1
-rwxr-xr-xkeyboards/lily58/ssd1306.h3
-rw-r--r--keyboards/yosino58/ssd1306.h3
-rw-r--r--quantum/pincontrol.h50
-rw-r--r--users/mtdjr/solenoid.h11
12 files changed, 34 insertions, 94 deletions
diff --git a/drivers/avr/apa102.c b/drivers/avr/apa102.c
index f4d97a158..b174b39b8 100644
--- a/drivers/avr/apa102.c
+++ b/drivers/avr/apa102.c
@@ -30,8 +30,8 @@
30void inline apa102_setleds(LED_TYPE *ledarray, uint16_t leds) { apa102_setleds_pin(ledarray, leds, _BV(RGB_DI_PIN & 0xF), _BV(RGB_CLK_PIN & 0xF)); } 30void inline apa102_setleds(LED_TYPE *ledarray, uint16_t leds) { apa102_setleds_pin(ledarray, leds, _BV(RGB_DI_PIN & 0xF), _BV(RGB_CLK_PIN & 0xF)); }
31 31
32void static inline apa102_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask_DI, uint8_t pinmask_CLK) { 32void static inline apa102_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask_DI, uint8_t pinmask_CLK) {
33 pinMode(RGB_DI_PIN, PinDirectionOutput); 33 setPinOutput(RGB_DI_PIN);
34 pinMode(RGB_CLK_PIN, PinDirectionOutput); 34 setPinOutput(RGB_CLK_PIN);
35 35
36 apa102_send_array((uint8_t *)ledarray, leds) 36 apa102_send_array((uint8_t *)ledarray, leds)
37} 37}
@@ -90,7 +90,7 @@ void apa102_end_frame(uint16_t leds) {
90void apa102_send_byte(uint8_t byte) { 90void apa102_send_byte(uint8_t byte) {
91 uint8_t i; 91 uint8_t i;
92 for (i = 0; i < 8; i++) { 92 for (i = 0; i < 8; i++) {
93 digitalWrite(RGB_DI_PIN, !!(byte & (1 << (7-i))); 93 writePin(RGB_DI_PIN, !!(byte & (1 << (7 - i))));
94 digitalWrite(RGB_CLK_PIN, PinLevelHigh); 94 writePinHigh(RGB_CLK_PIN);
95 } 95 }
96} 96}
diff --git a/drivers/avr/ssd1306.h b/drivers/avr/ssd1306.h
index 825b0d7d5..9669d1b7e 100644
--- a/drivers/avr/ssd1306.h
+++ b/drivers/avr/ssd1306.h
@@ -3,7 +3,6 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include <stdio.h> 5#include <stdio.h>
6#include "pincontrol.h"
7#include "config.h" 6#include "config.h"
8 7
9enum ssd1306_cmds { 8enum ssd1306_cmds {
diff --git a/keyboards/40percentclub/nano/keymaps/drashna/keymap.c b/keyboards/40percentclub/nano/keymaps/drashna/keymap.c
index 998e55d5b..f5d0787ee 100644
--- a/keyboards/40percentclub/nano/keymaps/drashna/keymap.c
+++ b/keyboards/40percentclub/nano/keymaps/drashna/keymap.c
@@ -1,7 +1,6 @@
1#include "drashna.h" 1#include "drashna.h"
2#include "analog.h" 2#include "analog.h"
3#include "pointing_device.h" 3#include "pointing_device.h"
4#include "pincontrol.h"
5 4
6#define KC_X0 LT(_FN, KC_ESC) 5#define KC_X0 LT(_FN, KC_ESC)
7 6
diff --git a/keyboards/claw44/ssd1306.h b/keyboards/claw44/ssd1306.h
index ea8c92328..0ca093093 100644
--- a/keyboards/claw44/ssd1306.h
+++ b/keyboards/claw44/ssd1306.h
@@ -2,7 +2,6 @@
2 2
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdio.h> 4#include <stdio.h>
5#include "pincontrol.h"
6#include "action.h" 5#include "action.h"
7 6
8enum ssd1306_cmds { 7enum ssd1306_cmds {
@@ -88,4 +87,4 @@ void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
88void matrix_write_P(struct CharacterMatrix *matrix, const char *data); 87void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
89void matrix_render(struct CharacterMatrix *matrix); 88void matrix_render(struct CharacterMatrix *matrix);
90 89
91bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file 90bool process_record_gfx(uint16_t keycode, keyrecord_t *record);
diff --git a/keyboards/comet46/ssd1306.h b/keyboards/comet46/ssd1306.h
index ea8c92328..0ca093093 100644
--- a/keyboards/comet46/ssd1306.h
+++ b/keyboards/comet46/ssd1306.h
@@ -2,7 +2,6 @@
2 2
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdio.h> 4#include <stdio.h>
5#include "pincontrol.h"
6#include "action.h" 5#include "action.h"
7 6
8enum ssd1306_cmds { 7enum ssd1306_cmds {
@@ -88,4 +87,4 @@ void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
88void matrix_write_P(struct CharacterMatrix *matrix, const char *data); 87void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
89void matrix_render(struct CharacterMatrix *matrix); 88void matrix_render(struct CharacterMatrix *matrix);
90 89
91bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file 90bool process_record_gfx(uint16_t keycode, keyrecord_t *record);
diff --git a/keyboards/converter/palm_usb/matrix.c b/keyboards/converter/palm_usb/matrix.c
index 49212f2ef..590b5eea3 100644
--- a/keyboards/converter/palm_usb/matrix.c
+++ b/keyboards/converter/palm_usb/matrix.c
@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include QMK_KEYBOARD_H 20#include QMK_KEYBOARD_H
21#include "protocol/serial.h" 21#include "protocol/serial.h"
22#include "timer.h" 22#include "timer.h"
23#include "pincontrol.h"
24 23
25 24
26/* 25/*
@@ -96,27 +95,27 @@ void pins_init(void) {
96 // set pins for pullups, Rts , power &etc. 95 // set pins for pullups, Rts , power &etc.
97 96
98 //print ("pins setup\n"); 97 //print ("pins setup\n");
99 pinMode(VCC_PIN, PinDirectionOutput); 98 setPinOutput(VCC_PIN);
100 digitalWrite(VCC_PIN, PinLevelLow); 99 writePinLow(VCC_PIN);
101 100
102#if ( HANDSPRING == 0) 101#if ( HANDSPRING == 0)
103 102
104#ifdef CY835 103#ifdef CY835
105 pinMode(GND_PIN, PinDirectionOutput); 104 setPinOutput(GND_PIN);
106 digitalWrite(GND_PIN, PinLevelLow); 105 writePinLow(GND_PIN);
107 106
108 pinMode(PULLDOWN_PIN, PinDirectionOutput); 107 setPinOutput(PULLDOWN_PIN);
109 digitalWrite(PULLDOWN_PIN, PinLevelLow); 108 writePinLow(PULLDOWN_PIN);
110#endif 109#endif
111 110
112 pinMode(DCD_PIN, PinDirectionInput); 111 setPinInput(DCD_PIN);
113 pinMode(RTS_PIN, PinDirectionInput); 112 setPinInput(RTS_PIN);
114#endif 113#endif
115 114
116/* check that the other side isn't powered up. 115/* check that the other side isn't powered up.
117 test=digitalRead(DCD_PIN); 116 test=readPin(DCD_PIN);
118 xprintf("b%02X:", test); 117 xprintf("b%02X:", test);
119 test=digitalRead(RTS_PIN); 118 test=readPin(RTS_PIN);
120 xprintf("%02X\n", test); 119 xprintf("%02X\n", test);
121*/ 120*/
122 121
@@ -129,20 +128,20 @@ uint8_t rts_reset(void) {
129// On boot, we keep rts as input, then switch roles here 128// On boot, we keep rts as input, then switch roles here
130// on leaving sleep, we toggle the same way 129// on leaving sleep, we toggle the same way
131 130
132 firstread=digitalRead(RTS_PIN); 131 firstread=readPin(RTS_PIN);
133 // printf("r%02X:", firstread); 132 // printf("r%02X:", firstread);
134 133
135 pinMode(RTS_PIN, PinDirectionOutput); 134 setPinOutput(RTS_PIN);
136 135
137 if (firstread == PinLevelHigh) { 136 if (firstread) {
138 digitalWrite(RTS_PIN, PinLevelLow); 137 writePinLow(RTS_PIN);
139 } 138 }
140 _delay_ms(10); 139 _delay_ms(10);
141 digitalWrite(RTS_PIN, PinLevelHigh); 140 writePinHigh(RTS_PIN);
142 141
143 142
144/* the future is Arm 143/* the future is Arm
145 if (palReadPad(RTS_PIN_IOPRT) == PinLevelLow) 144 if (!palReadPad(RTS_PIN_IOPRT))
146 { 145 {
147 _delay_ms(10); 146 _delay_ms(10);
148 palSetPadMode(RTS_PINn_IOPORT, PinDirectionOutput_PUSHPULL); 147 palSetPadMode(RTS_PINn_IOPORT, PinDirectionOutput_PUSHPULL);
@@ -224,9 +223,9 @@ uint8_t handspring_handshake(void) {
224} 223}
225 224
226uint8_t handspring_reset(void) { 225uint8_t handspring_reset(void) {
227 digitalWrite(VCC_PIN, PinLevelLow); 226 writePinLow(VCC_PIN);
228 _delay_ms(5); 227 _delay_ms(5);
229 digitalWrite(VCC_PIN, PinLevelHigh); 228 writePinHigh(VCC_PIN);
230 229
231 if ( handspring_handshake() ) { 230 if ( handspring_handshake() ) {
232 last_activity = timer_read(); 231 last_activity = timer_read();
@@ -250,7 +249,7 @@ void matrix_init(void)
250#endif 249#endif
251 250
252 print("power up\n"); 251 print("power up\n");
253 digitalWrite(VCC_PIN, PinLevelHigh); 252 writePinHigh(VCC_PIN);
254 253
255 // wait for DCD strobe from keyboard - it will do this 254 // wait for DCD strobe from keyboard - it will do this
256 // up to 3 times, then the board needs the RTS toggled to try again 255 // up to 3 times, then the board needs the RTS toggled to try again
@@ -265,7 +264,7 @@ void matrix_init(void)
265 } 264 }
266 265
267#else /// Palm / HP device with DCD 266#else /// Palm / HP device with DCD
268 while( digitalRead(DCD_PIN) != PinLevelHigh ) {;} 267 while( !readPin(DCD_PIN) ) {;}
269 print("dcd\n"); 268 print("dcd\n");
270 269
271 rts_reset(); // at this point the keyboard should think all is well. 270 rts_reset(); // at this point the keyboard should think all is well.
diff --git a/keyboards/crkbd/ssd1306.h b/keyboards/crkbd/ssd1306.h
index ea8c92328..0ca093093 100644
--- a/keyboards/crkbd/ssd1306.h
+++ b/keyboards/crkbd/ssd1306.h
@@ -2,7 +2,6 @@
2 2
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdio.h> 4#include <stdio.h>
5#include "pincontrol.h"
6#include "action.h" 5#include "action.h"
7 6
8enum ssd1306_cmds { 7enum ssd1306_cmds {
@@ -88,4 +87,4 @@ void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
88void matrix_write_P(struct CharacterMatrix *matrix, const char *data); 87void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
89void matrix_render(struct CharacterMatrix *matrix); 88void matrix_render(struct CharacterMatrix *matrix);
90 89
91bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file 90bool process_record_gfx(uint16_t keycode, keyrecord_t *record);
diff --git a/keyboards/helix/local_drivers/ssd1306.h b/keyboards/helix/local_drivers/ssd1306.h
index 9cf6983b7..f9f91c6fe 100644
--- a/keyboards/helix/local_drivers/ssd1306.h
+++ b/keyboards/helix/local_drivers/ssd1306.h
@@ -3,7 +3,6 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include <stdio.h> 5#include <stdio.h>
6#include "pincontrol.h"
7#include "action.h" 6#include "action.h"
8 7
9enum ssd1306_cmds { 8enum ssd1306_cmds {
diff --git a/keyboards/lily58/ssd1306.h b/keyboards/lily58/ssd1306.h
index ea8c92328..0ca093093 100755
--- a/keyboards/lily58/ssd1306.h
+++ b/keyboards/lily58/ssd1306.h
@@ -2,7 +2,6 @@
2 2
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdio.h> 4#include <stdio.h>
5#include "pincontrol.h"
6#include "action.h" 5#include "action.h"
7 6
8enum ssd1306_cmds { 7enum ssd1306_cmds {
@@ -88,4 +87,4 @@ void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
88void matrix_write_P(struct CharacterMatrix *matrix, const char *data); 87void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
89void matrix_render(struct CharacterMatrix *matrix); 88void matrix_render(struct CharacterMatrix *matrix);
90 89
91bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file 90bool process_record_gfx(uint16_t keycode, keyrecord_t *record);
diff --git a/keyboards/yosino58/ssd1306.h b/keyboards/yosino58/ssd1306.h
index de0a9a02a..acaf6217e 100644
--- a/keyboards/yosino58/ssd1306.h
+++ b/keyboards/yosino58/ssd1306.h
@@ -2,7 +2,6 @@
2 2
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdio.h> 4#include <stdio.h>
5#include "pincontrol.h"
6#include "action.h" 5#include "action.h"
7 6
8enum ssd1306_cmds { 7enum ssd1306_cmds {
@@ -93,4 +92,4 @@ void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
93void matrix_write_P(struct CharacterMatrix *matrix, const char *data); 92void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
94void matrix_render(struct CharacterMatrix *matrix); 93void matrix_render(struct CharacterMatrix *matrix);
95 94
96bool process_record_gfx(uint16_t keycode, keyrecord_t *record); \ No newline at end of file 95bool process_record_gfx(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/pincontrol.h b/quantum/pincontrol.h
deleted file mode 100644
index 204fddf30..000000000
--- a/quantum/pincontrol.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/* Copyright 2016 Wez Furlong
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
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/>.
15 */
16#pragma once
17// Some helpers for controlling gpio pins
18#include <avr/io.h>
19
20enum {
21 PinDirectionInput = 0,
22 PinDirectionOutput = 1,
23 PinLevelHigh = 1,
24 PinLevelLow = 0,
25};
26
27// ex: pinMode(B0, PinDirectionOutput);
28static inline void pinMode(uint8_t pin, int mode) {
29 uint8_t bv = _BV(pin & 0xf);
30 if (mode == PinDirectionOutput) {
31 _SFR_IO8((pin >> 4) + 1) |= bv;
32 } else {
33 _SFR_IO8((pin >> 4) + 1) &= ~bv;
34 _SFR_IO8((pin >> 4) + 2) &= ~bv;
35 }
36}
37
38// ex: digitalWrite(B0, PinLevelHigh);
39static inline void digitalWrite(uint8_t pin, int mode) {
40 uint8_t bv = _BV(pin & 0xf);
41 if (mode == PinLevelHigh) {
42 _SFR_IO8((pin >> 4) + 2) |= bv;
43 } else {
44 _SFR_IO8((pin >> 4) + 2) &= ~bv;
45 }
46}
47
48// Return true if the pin is HIGH
49// digitalRead(B0)
50static inline bool digitalRead(uint8_t pin) { return _SFR_IO8(pin >> 4) & _BV(pin & 0xf); }
diff --git a/users/mtdjr/solenoid.h b/users/mtdjr/solenoid.h
index a911bf794..4ef329b4a 100644
--- a/users/mtdjr/solenoid.h
+++ b/users/mtdjr/solenoid.h
@@ -2,7 +2,6 @@
2#define SOLENOID_H 2#define SOLENOID_H
3 3
4#include <timer.h> 4#include <timer.h>
5#include "pincontrol.h"
6 5
7 6
8#define SOLENOID_DEFAULT_DWELL 12 7#define SOLENOID_DEFAULT_DWELL 12
@@ -45,7 +44,7 @@ void solenoid_toggle(void) {
45} 44}
46 45
47void solenoid_stop(void) { 46void solenoid_stop(void) {
48 digitalWrite(SOLENOID_PIN, PinLevelLow); 47 writePinLow(SOLENOID_PIN);
49 solenoid_on = false; 48 solenoid_on = false;
50 solenoid_buzzing = false; 49 solenoid_buzzing = false;
51} 50}
@@ -59,7 +58,7 @@ void solenoid_fire(void) {
59 solenoid_on = true; 58 solenoid_on = true;
60 solenoid_buzzing = true; 59 solenoid_buzzing = true;
61 solenoid_start = timer_read(); 60 solenoid_start = timer_read();
62 digitalWrite(SOLENOID_PIN, PinLevelHigh); 61 writePinHigh(SOLENOID_PIN);
63} 62}
64 63
65void solenoid_check(void) { 64void solenoid_check(void) {
@@ -80,20 +79,20 @@ void solenoid_check(void) {
80 if (elapsed / SOLENOID_MIN_DWELL % 2 == 0){ 79 if (elapsed / SOLENOID_MIN_DWELL % 2 == 0){
81 if (!solenoid_buzzing) { 80 if (!solenoid_buzzing) {
82 solenoid_buzzing = true; 81 solenoid_buzzing = true;
83 digitalWrite(SOLENOID_PIN, PinLevelHigh); 82 writePinHigh(SOLENOID_PIN);
84 } 83 }
85 } 84 }
86 else { 85 else {
87 if (solenoid_buzzing) { 86 if (solenoid_buzzing) {
88 solenoid_buzzing = false; 87 solenoid_buzzing = false;
89 digitalWrite(SOLENOID_PIN, PinLevelLow); 88 writePinLow(SOLENOID_PIN);
90 } 89 }
91 } 90 }
92 } 91 }
93} 92}
94 93
95void solenoid_setup(void) { 94void solenoid_setup(void) {
96 pinMode(SOLENOID_PIN, PinDirectionOutput); 95 setPinOutput(SOLENOID_PIN);
97} 96}
98 97
99#endif 98#endif