diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
| commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
| tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/protocol/midi/bytequeue | |
| parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
| download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip | |
clang-format changes
Diffstat (limited to 'tmk_core/protocol/midi/bytequeue')
| -rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/bytequeue.c | 93 | ||||
| -rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/bytequeue.h | 59 | ||||
| -rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/interrupt_setting.c | 54 | ||||
| -rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/interrupt_setting.h | 33 |
4 files changed, 114 insertions, 125 deletions
diff --git a/tmk_core/protocol/midi/bytequeue/bytequeue.c b/tmk_core/protocol/midi/bytequeue/bytequeue.c index e43495632..e36a9e66b 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/bytequeue.c +++ b/tmk_core/protocol/midi/bytequeue/bytequeue.c | |||
| @@ -1,65 +1,62 @@ | |||
| 1 | //this is a single reader [maybe multiple writer?] byte queue | 1 | // this is a single reader [maybe multiple writer?] byte queue |
| 2 | //Copyright 2008 Alex Norman | 2 | // Copyright 2008 Alex Norman |
| 3 | //writen by Alex Norman | 3 | // writen by Alex Norman |
| 4 | // | 4 | // |
| 5 | //This file is part of avr-bytequeue. | 5 | // This file is part of avr-bytequeue. |
| 6 | // | 6 | // |
| 7 | //avr-bytequeue is free software: you can redistribute it and/or modify | 7 | // avr-bytequeue is free software: you can redistribute it and/or modify |
| 8 | //it under the terms of the GNU General Public License as published by | 8 | // it under the terms of the GNU General Public License as published by |
| 9 | //the Free Software Foundation, either version 3 of the License, or | 9 | // the Free Software Foundation, either version 3 of the License, or |
| 10 | //(at your option) any later version. | 10 | //(at your option) any later version. |
| 11 | // | 11 | // |
| 12 | //avr-bytequeue is distributed in the hope that it will be useful, | 12 | // avr-bytequeue is distributed in the hope that it will be useful, |
| 13 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | //GNU General Public License for more details. | 15 | // GNU General Public License for more details. |
| 16 | // | 16 | // |
| 17 | //You should have received a copy of the GNU General Public License | 17 | // You should have received a copy of the GNU General Public License |
| 18 | //along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | 18 | // along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | ||
| 20 | #include "bytequeue.h" | 20 | #include "bytequeue.h" |
| 21 | #include "interrupt_setting.h" | 21 | #include "interrupt_setting.h" |
| 22 | 22 | ||
| 23 | void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen){ | 23 | void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen) { |
| 24 | queue->length = arrayLen; | 24 | queue->length = arrayLen; |
| 25 | queue->data = dataArray; | 25 | queue->data = dataArray; |
| 26 | queue->start = queue->end = 0; | 26 | queue->start = queue->end = 0; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item){ | 29 | bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item) { |
| 30 | interrupt_setting_t setting = store_and_clear_interrupt(); | 30 | interrupt_setting_t setting = store_and_clear_interrupt(); |
| 31 | //full | 31 | // full |
| 32 | if(((queue->end + 1) % queue->length) == queue->start){ | 32 | if (((queue->end + 1) % queue->length) == queue->start) { |
| 33 | restore_interrupt_setting(setting); | 33 | restore_interrupt_setting(setting); |
| 34 | return false; | 34 | return false; |
| 35 | } else { | 35 | } else { |
| 36 | queue->data[queue->end] = item; | 36 | queue->data[queue->end] = item; |
| 37 | queue->end = (queue->end + 1) % queue->length; | 37 | queue->end = (queue->end + 1) % queue->length; |
| 38 | restore_interrupt_setting(setting); | 38 | restore_interrupt_setting(setting); |
| 39 | return true; | 39 | return true; |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | byteQueueIndex_t bytequeue_length(byteQueue_t * queue){ | 43 | byteQueueIndex_t bytequeue_length(byteQueue_t* queue) { |
| 44 | byteQueueIndex_t len; | 44 | byteQueueIndex_t len; |
| 45 | interrupt_setting_t setting = store_and_clear_interrupt(); | 45 | interrupt_setting_t setting = store_and_clear_interrupt(); |
| 46 | if(queue->end >= queue->start) | 46 | if (queue->end >= queue->start) |
| 47 | len = queue->end - queue->start; | 47 | len = queue->end - queue->start; |
| 48 | else | 48 | else |
| 49 | len = (queue->length - queue->start) + queue->end; | 49 | len = (queue->length - queue->start) + queue->end; |
| 50 | restore_interrupt_setting(setting); | 50 | restore_interrupt_setting(setting); |
| 51 | return len; | 51 | return len; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | //we don't need to avoid interrupts if there is only one reader | 54 | // we don't need to avoid interrupts if there is only one reader |
| 55 | uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index){ | 55 | uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index) { return queue->data[(queue->start + index) % queue->length]; } |
| 56 | return queue->data[(queue->start + index) % queue->length]; | ||
| 57 | } | ||
| 58 | 56 | ||
| 59 | //we just update the start index to remove elements | 57 | // we just update the start index to remove elements |
| 60 | void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove){ | 58 | void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove) { |
| 61 | interrupt_setting_t setting = store_and_clear_interrupt(); | 59 | interrupt_setting_t setting = store_and_clear_interrupt(); |
| 62 | queue->start = (queue->start + numToRemove) % queue->length; | 60 | queue->start = (queue->start + numToRemove) % queue->length; |
| 63 | restore_interrupt_setting(setting); | 61 | restore_interrupt_setting(setting); |
| 64 | } | 62 | } |
| 65 | |||
diff --git a/tmk_core/protocol/midi/bytequeue/bytequeue.h b/tmk_core/protocol/midi/bytequeue/bytequeue.h index e4a286134..33fb63a8c 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/bytequeue.h +++ b/tmk_core/protocol/midi/bytequeue/bytequeue.h | |||
| @@ -1,28 +1,28 @@ | |||
| 1 | //this is a single reader [maybe multiple writer?] byte queue | 1 | // this is a single reader [maybe multiple writer?] byte queue |
| 2 | //Copyright 2008 Alex Norman | 2 | // Copyright 2008 Alex Norman |
| 3 | //writen by Alex Norman | 3 | // writen by Alex Norman |
| 4 | // | 4 | // |
| 5 | //This file is part of avr-bytequeue. | 5 | // This file is part of avr-bytequeue. |
| 6 | // | 6 | // |
| 7 | //avr-bytequeue is free software: you can redistribute it and/or modify | 7 | // avr-bytequeue is free software: you can redistribute it and/or modify |
| 8 | //it under the terms of the GNU General Public License as published by | 8 | // it under the terms of the GNU General Public License as published by |
| 9 | //the Free Software Foundation, either version 3 of the License, or | 9 | // the Free Software Foundation, either version 3 of the License, or |
| 10 | //(at your option) any later version. | 10 | //(at your option) any later version. |
| 11 | // | 11 | // |
| 12 | //avr-bytequeue is distributed in the hope that it will be useful, | 12 | // avr-bytequeue is distributed in the hope that it will be useful, |
| 13 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | //GNU General Public License for more details. | 15 | // GNU General Public License for more details. |
| 16 | // | 16 | // |
| 17 | //You should have received a copy of the GNU General Public License | 17 | // You should have received a copy of the GNU General Public License |
| 18 | //along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | 18 | // along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | ||
| 20 | #ifndef BYTEQUEUE_H | 20 | #ifndef BYTEQUEUE_H |
| 21 | #define BYTEQUEUE_H | 21 | #define BYTEQUEUE_H |
| 22 | 22 | ||
| 23 | #ifdef __cplusplus | 23 | #ifdef __cplusplus |
| 24 | extern "C" { | 24 | extern "C" { |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | #include <inttypes.h> | 27 | #include <inttypes.h> |
| 28 | #include <stdbool.h> | 28 | #include <stdbool.h> |
| @@ -30,30 +30,29 @@ extern "C" { | |||
| 30 | typedef uint8_t byteQueueIndex_t; | 30 | typedef uint8_t byteQueueIndex_t; |
| 31 | 31 | ||
| 32 | typedef struct { | 32 | typedef struct { |
| 33 | byteQueueIndex_t start; | 33 | byteQueueIndex_t start; |
| 34 | byteQueueIndex_t end; | 34 | byteQueueIndex_t end; |
| 35 | byteQueueIndex_t length; | 35 | byteQueueIndex_t length; |
| 36 | uint8_t * data; | 36 | uint8_t* data; |
| 37 | } byteQueue_t; | 37 | } byteQueue_t; |
| 38 | 38 | ||
| 39 | //you must have a queue, an array of data which the queue will use, and the length of that array | 39 | // you must have a queue, an array of data which the queue will use, and the length of that array |
| 40 | void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen); | 40 | void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen); |
| 41 | 41 | ||
| 42 | //add an item to the queue, returns false if the queue is full | 42 | // add an item to the queue, returns false if the queue is full |
| 43 | bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item); | 43 | bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item); |
| 44 | 44 | ||
| 45 | //get the length of the queue | 45 | // get the length of the queue |
| 46 | byteQueueIndex_t bytequeue_length(byteQueue_t * queue); | 46 | byteQueueIndex_t bytequeue_length(byteQueue_t* queue); |
| 47 | 47 | ||
| 48 | //this grabs data at the index given [starting at queue->start] | 48 | // this grabs data at the index given [starting at queue->start] |
| 49 | uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index); | 49 | uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index); |
| 50 | 50 | ||
| 51 | //update the index in the queue to reflect data that has been dealt with | 51 | // update the index in the queue to reflect data that has been dealt with |
| 52 | void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove); | 52 | void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove); |
| 53 | 53 | ||
| 54 | #ifdef __cplusplus | 54 | #ifdef __cplusplus |
| 55 | } | 55 | } |
| 56 | #endif | ||
| 57 | |||
| 58 | #endif | 56 | #endif |
| 59 | 57 | ||
| 58 | #endif | ||
diff --git a/tmk_core/protocol/midi/bytequeue/interrupt_setting.c b/tmk_core/protocol/midi/bytequeue/interrupt_setting.c index 0ab8b5462..1be1fee97 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/interrupt_setting.c +++ b/tmk_core/protocol/midi/bytequeue/interrupt_setting.c | |||
| @@ -1,49 +1,43 @@ | |||
| 1 | //Copyright 20010 Alex Norman | 1 | // Copyright 20010 Alex Norman |
| 2 | //writen by Alex Norman | 2 | // writen by Alex Norman |
| 3 | // | 3 | // |
| 4 | //This file is part of avr-bytequeue. | 4 | // This file is part of avr-bytequeue. |
| 5 | // | 5 | // |
| 6 | //avr-bytequeue is free software: you can redistribute it and/or modify | 6 | // avr-bytequeue is free software: you can redistribute it and/or modify |
| 7 | //it under the terms of the GNU General Public License as published by | 7 | // it under the terms of the GNU General Public License as published by |
| 8 | //the Free Software Foundation, either version 3 of the License, or | 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | //(at your option) any later version. | 9 | //(at your option) any later version. |
| 10 | // | 10 | // |
| 11 | //avr-bytequeue is distributed in the hope that it will be useful, | 11 | // avr-bytequeue is distributed in the hope that it will be useful, |
| 12 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | //GNU General Public License for more details. | 14 | // GNU General Public License for more details. |
| 15 | // | 15 | // |
| 16 | //You should have received a copy of the GNU General Public License | 16 | // You should have received a copy of the GNU General Public License |
| 17 | //along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | 17 | // along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | ||
| 19 | 19 | // AVR specific code | |
| 20 | //AVR specific code | 20 | // should be able to port to other systems by simply providing chip specific |
| 21 | //should be able to port to other systems by simply providing chip specific | 21 | // implementations of the typedef and these functions |
| 22 | //implementations of the typedef and these functions | ||
| 23 | 22 | ||
| 24 | #include "interrupt_setting.h" | 23 | #include "interrupt_setting.h" |
| 25 | #if defined(__AVR__) | 24 | #if defined(__AVR__) |
| 26 | #include <avr/interrupt.h> | 25 | # include <avr/interrupt.h> |
| 27 | 26 | ||
| 28 | interrupt_setting_t store_and_clear_interrupt(void) { | 27 | interrupt_setting_t store_and_clear_interrupt(void) { |
| 29 | uint8_t sreg = SREG; | 28 | uint8_t sreg = SREG; |
| 30 | cli(); | 29 | cli(); |
| 31 | return sreg; | 30 | return sreg; |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | void restore_interrupt_setting(interrupt_setting_t setting) { | 33 | void restore_interrupt_setting(interrupt_setting_t setting) { SREG = setting; } |
| 35 | SREG = setting; | ||
| 36 | } | ||
| 37 | #elif defined(__arm__) | 34 | #elif defined(__arm__) |
| 38 | #include "ch.h" | 35 | # include "ch.h" |
| 39 | 36 | ||
| 40 | interrupt_setting_t store_and_clear_interrupt(void) { | 37 | interrupt_setting_t store_and_clear_interrupt(void) { |
| 41 | chSysLock(); | 38 | chSysLock(); |
| 42 | return 0; | 39 | return 0; |
| 43 | } | 40 | } |
| 44 | 41 | ||
| 45 | void restore_interrupt_setting(interrupt_setting_t setting) { | 42 | void restore_interrupt_setting(interrupt_setting_t setting) { chSysUnlock(); } |
| 46 | chSysUnlock(); | ||
| 47 | } | ||
| 48 | #endif | 43 | #endif |
| 49 | |||
diff --git a/tmk_core/protocol/midi/bytequeue/interrupt_setting.h b/tmk_core/protocol/midi/bytequeue/interrupt_setting.h index 053d02c9d..788f75d79 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/interrupt_setting.h +++ b/tmk_core/protocol/midi/bytequeue/interrupt_setting.h | |||
| @@ -1,39 +1,38 @@ | |||
| 1 | //Copyright 20010 Alex Norman | 1 | // Copyright 20010 Alex Norman |
| 2 | //writen by Alex Norman | 2 | // writen by Alex Norman |
| 3 | // | 3 | // |
| 4 | //This file is part of avr-bytequeue. | 4 | // This file is part of avr-bytequeue. |
| 5 | // | 5 | // |
| 6 | //avr-bytequeue is free software: you can redistribute it and/or modify | 6 | // avr-bytequeue is free software: you can redistribute it and/or modify |
| 7 | //it under the terms of the GNU General Public License as published by | 7 | // it under the terms of the GNU General Public License as published by |
| 8 | //the Free Software Foundation, either version 3 of the License, or | 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | //(at your option) any later version. | 9 | //(at your option) any later version. |
| 10 | // | 10 | // |
| 11 | //avr-bytequeue is distributed in the hope that it will be useful, | 11 | // avr-bytequeue is distributed in the hope that it will be useful, |
| 12 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | //GNU General Public License for more details. | 14 | // GNU General Public License for more details. |
| 15 | // | 15 | // |
| 16 | //You should have received a copy of the GNU General Public License | 16 | // You should have received a copy of the GNU General Public License |
| 17 | //along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | 17 | // along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | ||
| 19 | #ifndef INTERRUPT_SETTING_H | 19 | #ifndef INTERRUPT_SETTING_H |
| 20 | #define INTERRUPT_SETTING_H | 20 | #define INTERRUPT_SETTING_H |
| 21 | 21 | ||
| 22 | #ifdef __cplusplus | 22 | #ifdef __cplusplus |
| 23 | extern "C" { | 23 | extern "C" { |
| 24 | #endif | 24 | #endif |
| 25 | 25 | ||
| 26 | #include <inttypes.h> | 26 | #include <inttypes.h> |
| 27 | 27 | ||
| 28 | //AVR specific typedef | 28 | // AVR specific typedef |
| 29 | typedef uint8_t interrupt_setting_t; | 29 | typedef uint8_t interrupt_setting_t; |
| 30 | 30 | ||
| 31 | interrupt_setting_t store_and_clear_interrupt(void); | 31 | interrupt_setting_t store_and_clear_interrupt(void); |
| 32 | void restore_interrupt_setting(interrupt_setting_t setting); | 32 | void restore_interrupt_setting(interrupt_setting_t setting); |
| 33 | 33 | ||
| 34 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
| 35 | } | 35 | } |
| 36 | #endif | ||
| 37 | |||
| 38 | #endif | 36 | #endif |
| 39 | 37 | ||
| 38 | #endif | ||
