Commit 281454f7 authored by Matthias Wenzl's avatar Matthias Wenzl
Browse files

audio interface initial commit

parents
*~
*.o
src/*~
src/*.o
doc/html
doc/*.db
File added
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
/*
* Copyright (C) 2016 discover
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** @file adc.c
@brief ADC module (.c).
@date Apr 18, 2016
@author Katharina Ewers
@version 1.0
*/
/* Include required interfaces */
#include <stdbool.h>
#include <stdint.h>
#include <driverlib/sysctl.h>
#include <driverlib/adc.h>
#include <driverlib/timer.h>
#include <driverlib/interrupt.h>
#include <driverlib/gpio.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "ringbuffer.h"
#include "i2c_wrapper.h"
#include "g711_pcma_lookup.c"
#include "g711_pcmu_lookup.c"
/* Implemented interface */
#include "adc.h"
/* Global variables */
volatile int8_t adc_sample;
volatile int8_t pcma;
volatile uint32_t rdyflag;
RingBuffer_init(adc_buf, ADC_BUF_SIZE);
void ADCInitHW(void) {
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // ADC
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // GPIO Pin PE3
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Configure GPIO Pin PE3 as an ADC pin
ADCSequenceDisable(ADC0_BASE, SS0);
ADCSequenceConfigure(ADC0_BASE, FIRST_STEP, ADC_TRIGGER_TIMER, HIGHEST_PRIORITY);
ADCSequenceStepConfigure(ADC0_BASE, SS0, FIRST_STEP,
ADC_CTL_IE /* Issue interrupt upon completion */ |
ADC_CTL_END /* End of sample sequence */ |
ADC_CTL_CH0 /* Sample the value of Channel 0 */
);
ADCSequenceEnable(ADC0_BASE, SS0);
}
void ADCInitInt(void) {
/* Let the finishing of this sequence call an ISR */
rdyflag = 0;
ADCIntRegister(ADC0_BASE,SS0,ADC0IntHandler);
ADCIntClear(ADC0_BASE, SS0);
ADCIntEnable(ADC0_BASE, SS0);
}
void ADC0IntHandler(void) {
static uint32_t adc_val[8];
ADCIntClear(ADC0_BASE, SS0);
ADCSequenceDataGet(ADC0_BASE, SS0, adc_val);
if (rdyflag == 0) {
adc_sample = (int8_t)(((int32_t)adc_val[0] - 2048) >> 4); // Remove offset and cut off the last 4 bits
pcma = alaw_compress(adc_sample);
RingBuffer_write(&adc_buf, &(alaw_compress(adc_sample)), 1); // Write the result to the ring buffer
rdyflag = 1;
}
}
/*
* Copyright (C) 2016 discover
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** @file adc.h
@brief ADC module (.h).
@date Apr 18, 2016
@author Katharina Ewers
@version 1.0
*/
#define HIGHEST_PRIORITY 0 /**< Sequence priority */
#define FIRST_STEP 0 /**< First Sequence Step ID */
#define SS0 0 /**< Sample Sequencer 0 (SS0) ID */
/*! @def ADC_BUF_SIZE
@brief ADC ring buffer size.
@details RTP payload's size = 1474. 1 frame = 60 octets in R3 mode => 1 RTP packet can carry a maximum of 24 frames. 24*60 = 1440 octets.
*/
#define ADC_BUF_SIZE 1440
extern volatile int8_t adc_sample; ///< Latest ADC sample.
extern volatile int8_t pcma; ///< Latest ADC sample (A-law-encoded).
extern volatile uint32_t rdyflag; ///< READY flag to indicate an ADC sample is available.
/*! @typedef RingBuffer_t
@brief Forward declaration of RingBuffer_t.
*/
typedef struct RingBuffer RingBuffer_t;
extern RingBuffer_t adc_buf; ///< ADC Ring Buffer.
/**
* Initializes and configures ADC0.
* @param void
* @return void
*/
extern void ADCInitHW(void);
/**
* Configures interrupt for ADC0.
* @param void
* @return void
*/
extern void ADCInitInt(void);
/**
* Interrupt handler for ADC0.
* @param void
* @return void
*/
static void ADC0IntHandler(void);
//auto generated by g711 tool
#include <stdint.h>
#define alaw_compress(x) ALawCompressTable[(x)+127]
#define alaw_expand(x) ALawExpandTable[(x)+127]
static int8_t ALawCompressTable[255] = {-127, -127, -127, -126, -126, -126, -126, -126, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -123, -123, -123, -123, -123, -122, -122, -122, -122, -121, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118, -117, -117, -117, -117, -116, -116, -116, -115, -115, -115, -114, -114, -114, -114, -113, -113, -113, -112, -112, -111, -111, -111, -110, -110, -110, -109, -109, -108, -108, -108, -107, -107, -106, -106, -105, -105, -104, -104, -103, -103, -102, -102, -101, -101, -100, -100, -99, -98, -98, -97, -96, -96, -95, -94, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -80, -79, -77, -76, -74, -72, -70, -68, -66, -63, -60, -56, -52, -47, -40, -31, -16, 0, 16, 31, 40, 47, 52, 56, 60, 63, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 96, 97, 98, 98, 99, 100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108, 108, 109, 109, 110, 110, 110, 111, 111, 111, 112, 112, 113, 113, 113, 114, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117, 117, 117, 118, 118, 118, 118, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 127, 127, 127};
static int8_t ALawExpandTable[255] = {-127, -122, -117, -112, -107, -102, -98, -94, -90, -86, -83, -79, -76, -73, -69, -67, -64, -61, -58, -56, -54, -51, -49, -47, -45, -43, -41, -40, -38, -36, -35, -33, -32, -31, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -17, -16, -15, -15, -14, -14, -13, -12, -12, -11, -11, -10, -10, -10, -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -6, -6, -5, -5, -5, -5, -5, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 14, 14, 15, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 35, 36, 38, 40, 41, 43, 45, 47, 49, 51, 54, 56, 58, 61, 64, 67, 69, 73, 76, 79, 83, 86, 90, 94, 98, 102, 107, 112, 117, 122, 127};
//auto generated by g711 tool
#include <stdint.h>
#define mulaw_compress(x) MuLawCompressTable[(x)+127]
#define mulaw_expand(x) MuLawExpandTable[(x)+127]
static int8_t MuLawCompressTable[255] = {-127, -127, -127, -126, -126, -126, -126, -126, -126, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -123, -123, -123, -123, -122, -122, -122, -122, -122, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -119, -118, -118, -118, -118, -117, -117, -117, -116, -116, -116, -116, -115, -115, -115, -114, -114, -114, -113, -113, -113, -112, -112, -112, -111, -111, -111, -110, -110, -110, -109, -109, -108, -108, -108, -107, -107, -106, -106, -105, -105, -104, -104, -103, -103, -102, -102, -101, -101, -100, -100, -99, -98, -98, -97, -96, -96, -95, -94, -93, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -80, -79, -77, -76, -74, -72, -70, -68, -65, -62, -59, -55, -50, -45, -37, -25, 0, 25, 37, 45, 50, 55, 59, 62, 65, 68, 70, 72, 74, 76, 77, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 93, 94, 95, 96, 96, 97, 98, 98, 99, 100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108, 108, 109, 109, 110, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 116, 117, 117, 117, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123, 123, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 127, 127, 127};
static int8_t MuLawExpandTable[255] = {-127, -122, -116, -111, -107, -102, -98, -93, -89, -86, -82, -78, -75, -72, -69, -66, -63, -60, -58, -55, -53, -50, -48, -46, -44, -42, -40, -39, -37, -35, -34, -32, -31, -30, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -17, -16, -15, -15, -14, -13, -13, -12, -12, -11, -11, -10, -10, -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 34, 35, 37, 39, 40, 42, 44, 46, 48, 50, 53, 55, 58, 60, 63, 66, 69, 72, 75, 78, 82, 86, 89, 93, 98, 102, 107, 111, 116, 122, 127};
/*
* Copyright (C) 2016 discover
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** @file gpio.c
@brief GPIO module (.c).
@date Apr 18, 2016
@author Katharina Ewers
@version 1.0
*/
/* Include required interfaces */
#include <stdbool.h>
#include <stdint.h>
#include <driverlib/sysctl.h>
#include <driverlib/systick.h>
#include <driverlib/gpio.h>
#include <driverlib/timer.h>
#include <driverlib/uart.h>
#include <driverlib/pin_map.h>
#include "inc/hw_memmap.h"
#include "adc.h"
#include "timer.h"
/* Implemented interface */
#include "gpio.h"
void GPIOInitHW(void) {
uint32_t ui32_strength_pj; // Output drive strength of the button USR SW1 (PJ0) and SW2 (PJ1)
uint32_t ui32_pintype_pj; // Output drive type of the button USR SW1 (PJ0) and SW2 (PJ1)
/******************************************************
********** Initialize and configure buttons **********
******************************************************/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); // Enable USR SW1, USR SW2
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Set SW1 (PJ0) and SW2 (PJ1) to input
/* Configure pull-up resistor for the buttons SW1 (PJ0) and SW2 (PJ1) */
GPIOPadConfigGet(GPIO_PORTJ_BASE, GPIO_PIN_0, &ui32_strength_pj, &ui32_pintype_pj);
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, ui32_strength_pj, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigGet(GPIO_PORTJ_BASE, GPIO_PIN_1, &ui32_strength_pj, &ui32_pintype_pj);
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_1, ui32_strength_pj, GPIO_PIN_TYPE_STD_WPU);
}
void GPIOInitInt(void) {
GPIOIntRegister(GPIO_PORTJ_BASE, GPIOJIntHandler); // Register
GPIOIntTypeSet(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_FALLING_EDGE); // Set the type
GPIOIntClear(GPIO_PORTJ_BASE, GPIO_INT_PIN_0 | GPIO_INT_PIN_1);
GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0 | GPIO_INT_PIN_1); // Enable
}
void GPIOJIntHandler(void) {
switch(GPIOIntStatus(GPIO_PORTJ_BASE, true)) {
case GPIO_INT_PIN_0:
GPIOIntClear(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);
TimerControlTrigger(TIMER3_BASE, TIMER_A, true);
SysTickEnable();
break;
case GPIO_INT_PIN_1:
GPIOIntClear(GPIO_PORTJ_BASE, GPIO_INT_PIN_1);
TimerControlTrigger(TIMER3_BASE, TIMER_A, false);
SysTickDisable();
break;
default:
break;
}
}
/*
* Copyright (C) 2016 discover
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** @file gpio.h
@brief GPIO module (.h).
@date Apr 18, 2016
@author Katharina Ewers
@version 1.0
*/
/**
* Initializes and configures USR SW1, USR SW2 and LED D1.
* @param void
* @return void
*/
extern void GPIOInitHW(void);
/**
* Configures interrupts for USR SW1 and USR SW2.
* @param void
* @return void
*/
extern void GPIOInitInt(void);
/**
* Interrupt handler for Port J (USR SW1 and USR SW2).
* @param void
* @return void
*/
static void GPIOJIntHandler(void);
/*
* Copyright (C) 2015 discover
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* i2c_wrapper.c
*
* Created on: Apr 20, 2015
* Author: matthias,
* Modifications: michael, 09.06.2015
*/
#include "i2c_wrapper.h"
static struct transfer g_transfer_i2c[4];
irqfnTable_t isr_table[MAX_DEVICES] = {
i2c0_isr,
i2c2_isr,
i2c7_isr,
i2c8_isr,
};
struct i2c_mappings i2c_attributes[MAX_DEVICES] = {
/*i2c0*/{I2C0_BASE, SYSCTL_PERIPH_I2C0, SYSCTL_PERIPH_GPIOB, GPIO_PB2_I2C0SCL, GPIO_PB3_I2C0SDA, GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_PIN_3},
/*i2c2*/{I2C2_BASE, SYSCTL_PERIPH_I2C2, SYSCTL_PERIPH_GPION, GPIO_PN5_I2C2SCL, GPIO_PN4_I2C2SDA, GPIO_PORTN_BASE, GPIO_PIN_5, GPIO_PIN_4},
/*i2c7*/{I2C7_BASE, SYSCTL_PERIPH_I2C7, SYSCTL_PERIPH_GPIOD, GPIO_PD0_I2C7SCL, GPIO_PD1_I2C7SDA, GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_1},
/*i2c8*/{I2C8_BASE, SYSCTL_PERIPH_I2C8, SYSCTL_PERIPH_GPIOA, GPIO_PA2_I2C8SCL, GPIO_PA3_I2C8SDA, GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_3}
};
void i2c0_isr(void)
{
i2c_device_handler(&g_transfer_i2c[I2CM_0]);
}
void i2c2_isr(void)
{
i2c_device_handler(&g_transfer_i2c[I2CM_2]);
}
void i2c7_isr(void)
{
i2c_device_handler(&g_transfer_i2c[I2CM_7]);
}
void i2c8_isr(void)
{
i2c_device_handler(&g_transfer_i2c[I2CM_8]);
}
uint32_t i2c_init(uint8_t device_id,uint32_t sysclock_freq, bool bfast)
{
struct i2c_mappings *dev = NULL;
struct transfer *i2c_handle = NULL;
void (*i2c_isr)(void) = NULL;
if(device_id > (MAX_DEVICES-1))
return 0;
dev = (struct i2c_mappings *)&i2c_attributes[device_id];
i2c_handle = (struct transfer *)&g_transfer_i2c[device_id];
i2c_isr = isr_table[device_id];
/*init our handle*/
i2c_handle->base_addr = dev->base_addr;
i2c_handle->buf = NULL;
i2c_handle->wlen = 0;
i2c_handle->rlen = 0;
i2c_handle->ptr = 0;
i2c_handle->slave_addr = 0;
i2c_handle->state = IDLE;
SysCtlPeripheralEnable(dev->en_i2c);
SysCtlPeripheralEnable(dev->en_gpio);
GPIOPinConfigure(dev->scl_pincfg);
GPIOPinConfigure(dev->sda_pincfg);
GPIOPinTypeI2CSCL(dev->scl_sda_gpio_port,dev->scl_gpio_pin);
GPIOPinTypeI2C(dev->scl_sda_gpio_port,dev->sda_gpio_pin);