-
-
Notifications
You must be signed in to change notification settings - Fork 39.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e528087
commit fb4fe52
Showing
13 changed files
with
2,432 additions
and
0 deletions.
There are no files selected for viewing
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,93 @@ | ||
/* | ||
LUFA Library | ||
Copyright (C) Dean Camera, 2012. | ||
dean [at] fourwalledcubicle [dot] com | ||
www.lufa-lib.org | ||
*/ | ||
|
||
/* | ||
Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) | ||
Permission to use, copy, modify, distribute, and sell this | ||
software and its documentation for any purpose is hereby granted | ||
without fee, provided that the above copyright notice appear in | ||
all copies and that both that the copyright notice and this | ||
permission notice and warranty disclaimer appear in supporting | ||
documentation, and that the name of the author not be used in | ||
advertising or publicity pertaining to distribution of the | ||
software without specific, written prior permission. | ||
The author disclaim all warranties with regard to this | ||
software, including all implied warranties of merchantability | ||
and fitness. In no event shall the author be liable for any | ||
special, indirect or consequential damages or any damages | ||
whatsoever resulting from loss of use, data or profits, whether | ||
in an action of contract, negligence or other tortious action, | ||
arising out of or in connection with the use or performance of | ||
this software. | ||
*/ | ||
|
||
/** \file | ||
* \brief LUFA Library Configuration Header File | ||
* | ||
* This header file is used to configure LUFA's compile time options, | ||
* as an alternative to the compile time constants supplied through | ||
* a makefile. | ||
* | ||
* For information on what each token does, refer to the LUFA | ||
* manual section "Summary of Compile Tokens". | ||
*/ | ||
|
||
#ifndef _LUFA_CONFIG_H_ | ||
#define _LUFA_CONFIG_H_ | ||
|
||
#if (ARCH == ARCH_AVR8) | ||
|
||
/* Non-USB Related Configuration Tokens: */ | ||
// #define DISABLE_TERMINAL_CODES | ||
|
||
/* USB Class Driver Related Tokens: */ | ||
// #define HID_HOST_BOOT_PROTOCOL_ONLY | ||
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} | ||
// #define HID_USAGE_STACK_DEPTH {Insert Value Here} | ||
// #define HID_MAX_COLLECTIONS {Insert Value Here} | ||
// #define HID_MAX_REPORTITEMS {Insert Value Here} | ||
// #define HID_MAX_REPORT_IDS {Insert Value Here} | ||
// #define NO_CLASS_DRIVER_AUTOFLUSH | ||
|
||
/* General USB Driver Related Tokens: */ | ||
// #define ORDERED_EP_CONFIG | ||
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) | ||
#define USB_DEVICE_ONLY | ||
// #define USB_HOST_ONLY | ||
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here} | ||
// #define NO_LIMITED_CONTROLLER_CONNECT | ||
// #define NO_SOF_EVENTS | ||
|
||
/* USB Device Mode Driver Related Tokens: */ | ||
// #define USE_RAM_DESCRIPTORS | ||
#define USE_FLASH_DESCRIPTORS | ||
// #define USE_EEPROM_DESCRIPTORS | ||
// #define NO_INTERNAL_SERIAL | ||
#define FIXED_CONTROL_ENDPOINT_SIZE 8 | ||
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here} | ||
#define FIXED_NUM_CONFIGURATIONS 1 | ||
// #define CONTROL_ONLY_DEVICE | ||
// #define INTERRUPT_CONTROL_ENDPOINT | ||
// #define NO_DEVICE_REMOTE_WAKEUP | ||
// #define NO_DEVICE_SELF_POWER | ||
|
||
/* USB Host Mode Driver Related Tokens: */ | ||
// #define HOST_STATE_AS_GPIOR {Insert Value Here} | ||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here} | ||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} | ||
// #define NO_AUTO_VBUS_MANAGEMENT | ||
// #define INVERTED_VBUS_ENABLE_LINE | ||
|
||
#else | ||
|
||
#error Unsupported architecture for this LUFA configuration file. | ||
|
||
#endif | ||
#endif |
Large diffs are not rendered by default.
Oops, something went wrong.
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,65 @@ | ||
//this is a single reader [maybe multiple writer?] byte queue | ||
//Copyright 2008 Alex Norman | ||
//writen by Alex Norman | ||
// | ||
//This file is part of avr-bytequeue. | ||
// | ||
//avr-bytequeue 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 3 of the License, or | ||
//(at your option) any later version. | ||
// | ||
//avr-bytequeue 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 avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#include "bytequeue.h" | ||
#include "interrupt_setting.h" | ||
|
||
void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen){ | ||
queue->length = arrayLen; | ||
queue->data = dataArray; | ||
queue->start = queue->end = 0; | ||
} | ||
|
||
bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item){ | ||
interrupt_setting_t setting = store_and_clear_interrupt(); | ||
//full | ||
if(((queue->end + 1) % queue->length) == queue->start){ | ||
restore_interrupt_setting(setting); | ||
return false; | ||
} else { | ||
queue->data[queue->end] = item; | ||
queue->end = (queue->end + 1) % queue->length; | ||
restore_interrupt_setting(setting); | ||
return true; | ||
} | ||
} | ||
|
||
byteQueueIndex_t bytequeue_length(byteQueue_t * queue){ | ||
byteQueueIndex_t len; | ||
interrupt_setting_t setting = store_and_clear_interrupt(); | ||
if(queue->end >= queue->start) | ||
len = queue->end - queue->start; | ||
else | ||
len = (queue->length - queue->start) + queue->end; | ||
restore_interrupt_setting(setting); | ||
return len; | ||
} | ||
|
||
//we don't need to avoid interrupts if there is only one reader | ||
uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index){ | ||
return queue->data[(queue->start + index) % queue->length]; | ||
} | ||
|
||
//we just update the start index to remove elements | ||
void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove){ | ||
interrupt_setting_t setting = store_and_clear_interrupt(); | ||
queue->start = (queue->start + numToRemove) % queue->length; | ||
restore_interrupt_setting(setting); | ||
} | ||
|
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,59 @@ | ||
//this is a single reader [maybe multiple writer?] byte queue | ||
//Copyright 2008 Alex Norman | ||
//writen by Alex Norman | ||
// | ||
//This file is part of avr-bytequeue. | ||
// | ||
//avr-bytequeue 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 3 of the License, or | ||
//(at your option) any later version. | ||
// | ||
//avr-bytequeue 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 avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef BYTEQUEUE_H | ||
#define BYTEQUEUE_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
|
||
typedef uint8_t byteQueueIndex_t; | ||
|
||
typedef struct { | ||
byteQueueIndex_t start; | ||
byteQueueIndex_t end; | ||
byteQueueIndex_t length; | ||
uint8_t * data; | ||
} byteQueue_t; | ||
|
||
//you must have a queue, an array of data which the queue will use, and the length of that array | ||
void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen); | ||
|
||
//add an item to the queue, returns false if the queue is full | ||
bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item); | ||
|
||
//get the length of the queue | ||
byteQueueIndex_t bytequeue_length(byteQueue_t * queue); | ||
|
||
//this grabs data at the index given [starting at queue->start] | ||
uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index); | ||
|
||
//update the index in the queue to reflect data that has been dealt with | ||
void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#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,36 @@ | ||
//Copyright 20010 Alex Norman | ||
//writen by Alex Norman | ||
// | ||
//This file is part of avr-bytequeue. | ||
// | ||
//avr-bytequeue 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 3 of the License, or | ||
//(at your option) any later version. | ||
// | ||
//avr-bytequeue 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 avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
//AVR specific code | ||
//should be able to port to other systems by simply providing chip specific | ||
//implementations of the typedef and these functions | ||
|
||
#include "interrupt_setting.h" | ||
#include <avr/interrupt.h> | ||
|
||
interrupt_setting_t store_and_clear_interrupt(void) { | ||
uint8_t sreg = SREG; | ||
cli(); | ||
return sreg; | ||
} | ||
|
||
void restore_interrupt_setting(interrupt_setting_t setting) { | ||
SREG = setting; | ||
} | ||
|
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,39 @@ | ||
//Copyright 20010 Alex Norman | ||
//writen by Alex Norman | ||
// | ||
//This file is part of avr-bytequeue. | ||
// | ||
//avr-bytequeue 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 3 of the License, or | ||
//(at your option) any later version. | ||
// | ||
//avr-bytequeue 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 avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef INTERRUPT_SETTING_H | ||
#define INTERRUPT_SETTING_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <inttypes.h> | ||
|
||
//AVR specific typedef | ||
typedef uint8_t interrupt_setting_t; | ||
|
||
interrupt_setting_t store_and_clear_interrupt(void); | ||
void restore_interrupt_setting(interrupt_setting_t setting); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|
Oops, something went wrong.