You are on page 1of 2

/*

* AudioRegisterWrite.c
*
* This module is used to interface the Audio shift register on PortE
*
* Author: Paul Westhoff ME218A FAll 2017
*/

// the common headers for C99 types


#include <stdint.h>
#include <stdbool.h>

// the headers to access the GPIO subsystem


#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"

// the headers to access the TivaWare Library


#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

#include "termio.h"

#include "BITDEFS.H"
#include "ES_Port.h"

// readability defines
#define DATA BIT1HI //GPIO_PIN_1
#define DATA_HI BIT1HI
#define DATA_LO BIT1LO

#define SCLK BIT2HI //GPIO_PIN_2


#define SCLK_HI BIT2HI
#define SCLK_LO BIT2LO

#define RCLK BIT3HI //GPIO_PIN_3


#define RCLK_LO BIT3LO
#define RCLK_HI BIT3HI

#define GET_MSB_IN_LSB(x) ((x & 0x80) >> 7)

// an image of the last 8 bits written to the shift register


static uint8_t LocalRegisterImage = 0;

// Get the current register being output


uint8_t Audio_GetCurrentRegister(void)
{
return LocalRegisterImage;
}

// Outputs 8 new bits


void Audio_Write(uint8_t NewValue)
{
LocalRegisterImage = NewValue; // save a local copy

// Lower the register clock


HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + ALL_BITS)) &= RCLK_LO;

static uint8_t bitCount;


static uint8_t mostSigBit = 7;
static uint8_t output;

// Shift out the data while pulsing the shift clock


for (bitCount = 0; (bitCount <= mostSigBit); bitCount++)
{
// Test MSB of NewValue and output to Pin0
output = GET_MSB_IN_LSB(NewValue);

if (output)
{
HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + ALL_BITS)) |= DATA_HI;
}
else
{
HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + ALL_BITS)) &= DATA_LO;
}

// Pulse shift clock


HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + ALL_BITS)) |= SCLK_HI;
HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + ALL_BITS)) &= SCLK_LO;

// Shift NewValue left 1 bit


NewValue = NewValue << 1;
}

// Raise the register clock to latch the new data


HWREG(GPIO_PORTE_BASE + (GPIO_O_DATA + ALL_BITS)) |= RCLK_HI;
}

// Pulses only one trigger


void Audio_Trigger(uint8_t NewValue)
{
Audio_Write(NewValue);
// write all channels back to 1
Audio_Write(0xff);
}

You might also like