Fixed some filenames, added test code for writing to DAC

This commit is contained in:
A.M. Rowsell 2020-10-06 23:53:24 -04:00
parent 1eb171f3ae
commit b0735b0ba4
2 changed files with 33 additions and 28 deletions

View File

@ -6,7 +6,7 @@
*/
#include <xc.h>
#include "i2c.h"
#include "i2c.hpp"
/**
* @fn i2c::i2c
* @param speed the requested I2C bus speed

View File

@ -8,7 +8,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "fuses.h"
#include "fuses.hpp"
#include <xc.h>
#include <sys/attribs.h>
#include <stdint.h>
@ -33,13 +33,13 @@ volatile uint8_t currentClip = 0;
// Audio clip address table
#define AUDIO_SIZE 509176
const uint32_t audioSize[16] = {0x0000ba8d, 0x0000d063, 0x000069fa, 0x00007c3e,
0x000030b4, 0x0000c676, 0x000020fd, 0x00005314, 0x00002db8, 0x00002fbd,
0x000046c0, 0x0000bc92, 0x0000a257, 0x00002830, 0x00011790, 0x0000a5b7
const uint32_t audioSize[16] = { 0x0000ba8d, 0x0000d063, 0x000069fa, 0x00007c3e,
0x000030b4, 0x0000c676, 0x000020fd, 0x00005314, 0x00002db8, 0x00002fbd,
0x000046c0, 0x0000bc92, 0x0000a257, 0x00002830, 0x00011790, 0x0000a5b7
};
const uint32_t audioAddress[16] = {0x00, 0x0000ba8d, 0x00018af0, 0x0001f4ea,
0x00027128, 0x0002a1dc, 0x00036852, 0x0003894f, 0x0003dc63, 0x00040a1b,
0x000439d8, 0x00048098, 0x00053d2a, 0x0005df81, 0x000607b1, 0x00071f41
const uint32_t audioAddress[16] = { 0x00, 0x0000ba8d, 0x00018af0, 0x0001f4ea,
0x00027128, 0x0002a1dc, 0x00036852, 0x0003894f, 0x0003dc63, 0x00040a1b,
0x000439d8, 0x00048098, 0x00053d2a, 0x0005df81, 0x000607b1, 0x00071f41
};
#define dacAddress 0x62
@ -81,20 +81,22 @@ uint8_t initSystem(void) {
SYSKEY = 0x12345678; // lock SYSKEY
// set up button & LED
ANSELACLR = 0xFFFF;
ANSELBCLR = 0xFFFF;
ANSELCCLR = 0xFFFF; // clear all analog functions
TRISCSET = 0x20; // PC5 is button input
// set up LED
TRISCCLR = 0x01; // PC0 is LED
PORTCCLR = 0x01; // turn LED off at boot
CNENCSET = 0x20; // enable on PC5
CNPUCSET = 0x20; // pullup enable
CNCONCSET = 0x8000;
IFS1CLR = 0x8000;
// set up button with change interrupt
TRISASET = 0x200; // PA9 is button input
CNENASET = 0x200; // enable on PA9
CNPUASET = 0x200; // pullup enable
CNCONASET = 0x8000; // enable for port A
IFS1CLR = 0x2000;
IPC8SET = 0xC0000; // priority 3
//IEC1SET = 0x8000; // enable pin change interrupt port C
IEC1SET = 0x2000; // enable pin change interrupt port A
/* Set up SPI1 */
TRISACLR = 0x10;
@ -137,11 +139,11 @@ int main(void) {
i2c i2cBus(400e3, 10e6);
// this needs to be as early as possible, but after SPI and UART setup
// if(LATC & 0x20) {
// // if button is held down at boot, it's programming mode
// globalState = STATE_PROGRAMMING;
// flash.program();
// }
if(!(LATC & 0x20)) {
// if button is held down at boot, it's programming mode
globalState = STATE_PROGRAMMING;
flash.program();
}
const char testString[20] = "Welcome to Canada\n\r";
// main state machine loop
@ -188,15 +190,18 @@ extern "C" {
}
void __ISR(_CHANGE_NOTICE_VECTOR, IPL3AUTO) PinChangeHandler(void) {
// button is pushed
if (globalState == STATE_PLAYING) {
return; // do nothing, we're already playing
if((IFS1 & 0x2000) || (CNSTATA & 0x200)) {
if(PORTA) ; // dummy read to reset change notice
// button is pushed
if (globalState == STATE_PLAYING) {
return; // do nothing, we're already playing
}
// pick a random number
currentClip += 1;
currentClip = currentClip % 8; // roll back around
globalState = STATE_PLAYING;
IFS1CLR = 0x00002000;
}
// pick a random number
currentClip += 1;
currentClip = currentClip % 8; // roll back around
globalState = STATE_PLAYING;
IFS0CLR = 0x00000100;
}
} // end extern C