TFT

Dependencies:   mbed

Fork of Ovation_Controller_1 by Andrew R

Committer:
bf1891
Date:
Thu Aug 28 15:18:07 2014 +0000
Revision:
3:92845c139aca
Parent:
2:67e16df2c89a
publish;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewcrussell 1:ecf8078bf531 1 /*******************************************************************/
andrewcrussell 1:ecf8078bf531 2 /************* Dec 22 2010 ************************/
andrewcrussell 1:ecf8078bf531 3 /************* V.1a ************************/
andrewcrussell 2:67e16df2c89a 4 /************* Balanced Stereo Pre-amplifer Control Program ********/
andrewcrussell 1:ecf8078bf531 5 #include "mbed.h"
andrewcrussell 1:ecf8078bf531 6 #include "system_defines.h"
andrewcrussell 1:ecf8078bf531 7 #include "stdlib.h"
andrewcrussell 1:ecf8078bf531 8 #include "font_1.h"
andrewcrussell 1:ecf8078bf531 9 #include "stdlib.h"
andrewcrussell 1:ecf8078bf531 10 #include "string.h"
andrewcrussell 1:ecf8078bf531 11 #include "math.h"
andrewcrussell 1:ecf8078bf531 12 /* global defines */
andrewcrussell 1:ecf8078bf531 13 int volume;
andrewcrussell 1:ecf8078bf531 14 int balance_left =0;
andrewcrussell 1:ecf8078bf531 15 int balance_right=0;
andrewcrussell 1:ecf8078bf531 16 int bright=8; /* this is the backlight brightness */
andrewcrussell 1:ecf8078bf531 17 int relay=0; /* this is just a counter */
andrewcrussell 1:ecf8078bf531 18 unsigned int control = 0; /* for the control outputs on the CPU board. This is the intial setting */
andrewcrussell 1:ecf8078bf531 19 unsigned int controls = 0; /* this is temporary storage value for control above used in power up and power down */
andrewcrussell 1:ecf8078bf531 20 int unsigned inputrelay=1; /* inputrelay holds the bit position of the selected relay */
andrewcrussell 1:ecf8078bf531 21 int pwrupvol=1;
andrewcrussell 1:ecf8078bf531 22 int power=0; /* set to 64 to turn it ON */
andrewcrussell 1:ecf8078bf531 23 int loopgain=0; /*set to 32 to turn it ON */
andrewcrussell 1:ecf8078bf531 24 int trigger=0; /* set to 16 to turn it ON */
andrewcrussell 1:ecf8078bf531 25 int mutebit=0; /* set to 1 to turn it ON */
andrewcrussell 1:ecf8078bf531 26 int hpmutebit=0; /* set to 127 to turn it ON */
andrewcrussell 1:ecf8078bf531 27 int recloop1bit=0; /*set to 2 to turn it ON */
andrewcrussell 2:67e16df2c89a 28 char remcon[6], ch[6];//were 10
andrewcrussell 1:ecf8078bf531 29 int remcontoken;
andrewcrussell 1:ecf8078bf531 30 int remaction;
andrewcrussell 2:67e16df2c89a 31 int rctimeoutflag;
andrewcrussell 1:ecf8078bf531 32 int r=0, k=0; /* these are counters used in the remote control routine */
andrewcrussell 1:ecf8078bf531 33 int flag=0; /* this fetches the command control code - remote or via f/panel PB's */
andrewcrussell 2:67e16df2c89a 34 float lightlevel;
andrewcrussell 1:ecf8078bf531 35 /********************** system constants ********************/
andrewcrussell 2:67e16df2c89a 36 // baclight bit position defines
andrewcrussell 2:67e16df2c89a 37 #define stripbacklight ~61440
andrewcrussell 1:ecf8078bf531 38 #define HIGH 1;
andrewcrussell 1:ecf8078bf531 39 #define LOW 0;
andrewcrussell 1:ecf8078bf531 40 //#define TRUE 1;
andrewcrussell 1:ecf8078bf531 41 #define FALSE 0;
andrewcrussell 1:ecf8078bf531 42 #define incdec 1;
andrewcrussell 2:67e16df2c89a 43 #define VOLA(p21);
andrewcrussell 2:67e16df2c89a 44 #define VOLB(p22);
andrewcrussell 2:67e16df2c89a 45 #define VOLPB(p23);
andrewcrussell 2:67e16df2c89a 46 #define IPSELA(p24);
andrewcrussell 2:67e16df2c89a 47 #define IPSELB(p25);
andrewcrussell 2:67e16df2c89a 48 #define IPSELPB(p26);
andrewcrussell 2:67e16df2c89a 49 #define SERIN(p27);
andrewcrussell 2:67e16df2c89a 50 #define STR_LENGTH 7
andrewcrussell 2:67e16df2c89a 51 #define STR_LENGTH_1 5
andrewcrussell 2:67e16df2c89a 52 char temp_string[STR_LENGTH_1 ];
andrewcrussell 1:ecf8078bf531 53 /*********** these are the input select relay bit position assignments **********/
andrewcrussell 1:ecf8078bf531 54 #define Aux2 4
andrewcrussell 1:ecf8078bf531 55 #define Aux1 8
andrewcrussell 1:ecf8078bf531 56 #define Recorder 16
andrewcrussell 1:ecf8078bf531 57 #define CD 32
andrewcrussell 1:ecf8078bf531 58 #define Phono 64
andrewcrussell 2:67e16df2c89a 59 /********************** declare all Graphic.h here AFTER the global defines**********************/
andrewcrussell 2:67e16df2c89a 60 #include "Graphic.h"
andrewcrussell 1:ecf8078bf531 61
andrewcrussell 1:ecf8078bf531 62 /********************** declare all interrupt input pins here**********************/
andrewcrussell 2:67e16df2c89a 63 InterruptIn volumein(p21); /* interuppt from the volume control encoder */
andrewcrussell 2:67e16df2c89a 64 InterruptIn inputsel(p24); /* for the input select encoder */
andrewcrussell 2:67e16df2c89a 65 InterruptIn mutesw(p26); /* this mutes the output - pb att to the sel encoder */
andrewcrussell 2:67e16df2c89a 66 InterruptIn powersw(p23); /* this turns the main power on-off. Att. to the vol control encoder */
andrewcrussell 1:ecf8078bf531 67 Timeout timeout; /* remote control timeout */
andrewcrussell 1:ecf8078bf531 68
andrewcrussell 1:ecf8078bf531 69 /********************** mbed HALT mode (from Igor Skochinsky) ****************************/
andrewcrussell 1:ecf8078bf531 70 /* note: this will not work if the usb is connected, if local files, */
andrewcrussell 1:ecf8078bf531 71 /* or printf statements are used. Disconnect USB to get this to work */
andrewcrussell 1:ecf8078bf531 72 void halt() {
andrewcrussell 1:ecf8078bf531 73 #if defined(TARGET_LPC1768)
andrewcrussell 1:ecf8078bf531 74 __wfi(); // (enter sleep mode and) wait for interrupt
andrewcrussell 1:ecf8078bf531 75 #else
andrewcrussell 1:ecf8078bf531 76 LPC_SC->PCON |= 1; // set PM0 = 1: enter idle mode (assuming PM1 and PM2 are 0)
andrewcrussell 1:ecf8078bf531 77 #endif
andrewcrussell 1:ecf8078bf531 78 }
andrewcrussell 1:ecf8078bf531 79 /********************** how to disable interrupts ****************************/
andrewcrussell 1:ecf8078bf531 80 //__disable_irq(); // Disable Interrupts
andrewcrussell 1:ecf8078bf531 81 //__enable_irq(); // Enable Interrupts
andrewcrussell 2:67e16df2c89a 82 /************************* read the light sensor *****************************/
andrewcrussell 1:ecf8078bf531 83 void lightsensor() {
andrewcrussell 1:ecf8078bf531 84 AnalogIn light(p20); /* fetch the light intensity */
andrewcrussell 2:67e16df2c89a 85 lightlevel=light.read(); /* fetch the light intensity */
andrewcrussell 2:67e16df2c89a 86 //printf("\n\rlight level= (%f)",light.read());
andrewcrussell 1:ecf8078bf531 87 }
andrewcrussell 2:67e16df2c89a 88
andrewcrussell 2:67e16df2c89a 89 /**************************** remote control IRQ ****************************/
andrewcrussell 1:ecf8078bf531 90 void remotecontrol(void) {
andrewcrussell 1:ecf8078bf531 91 int q=0;
andrewcrussell 1:ecf8078bf531 92 int z=0;
andrewcrussell 2:67e16df2c89a 93 myled=!myled; /* just to let us know we are looping through here */
andrewcrussell 2:67e16df2c89a 94
andrewcrussell 1:ecf8078bf531 95 do {
andrewcrussell 1:ecf8078bf531 96 remcon[z]=getc(remote);
andrewcrussell 2:67e16df2c89a 97 //printf("%c\n\r",remcon[z]);
andrewcrussell 1:ecf8078bf531 98 z++;
andrewcrussell 1:ecf8078bf531 99 } while (z<6);
andrewcrussell 2:67e16df2c89a 100 flag=atoi(remcon);
andrewcrussell 2:67e16df2c89a 101 //flag=remaction; //flag is either a valid command, or its a zero which means no valid command
andrewcrussell 2:67e16df2c89a 102 //printf("%d\n\r", flag);
andrewcrussell 2:67e16df2c89a 103 //printf("%d\n\r", remaction);
andrewcrussell 1:ecf8078bf531 104 /* here we flush everything to make sure that any garbage entries do not remain */
andrewcrussell 1:ecf8078bf531 105 /* because what we got in from the serial link was not a valid string */
andrewcrussell 2:67e16df2c89a 106 for (q=0;q<6;q++) { //flush the uart buffer which is 16 bytes deep (was originally set to 8)
andrewcrussell 2:67e16df2c89a 107 remcon[q]=(' '); //* clean it up for the next cycle */
andrewcrussell 2:67e16df2c89a 108 }
andrewcrussell 1:ecf8078bf531 109 remcontoken=1;
andrewcrussell 2:67e16df2c89a 110 myled=!myled;
andrewcrussell 2:67e16df2c89a 111
andrewcrussell 2:67e16df2c89a 112 }
andrewcrussell 1:ecf8078bf531 113 /*********** Power ON/OFF IRQ **********/
andrewcrussell 1:ecf8078bf531 114 void power1() {
andrewcrussell 2:67e16df2c89a 115 wait_ms(10); //was 10ms
andrewcrussell 1:ecf8078bf531 116 flag=9261;
andrewcrussell 1:ecf8078bf531 117 remcontoken=0;
andrewcrussell 1:ecf8078bf531 118 }
andrewcrussell 1:ecf8078bf531 119 /*************** Mute IRQ **************/
andrewcrussell 1:ecf8078bf531 120 void mute1() {
andrewcrussell 2:67e16df2c89a 121 wait_ms(10); //was 10ms
andrewcrussell 1:ecf8078bf531 122 flag=9241;
andrewcrussell 1:ecf8078bf531 123 remcontoken=0;
andrewcrussell 1:ecf8078bf531 124 }
andrewcrussell 1:ecf8078bf531 125 /************ Input Select IRQ ********/
andrewcrussell 1:ecf8078bf531 126 void inputsel1() {
andrewcrussell 1:ecf8078bf531 127 wait_ms(10);
andrewcrussell 1:ecf8078bf531 128 flag=9231;
andrewcrussell 1:ecf8078bf531 129 remcontoken=0;
andrewcrussell 1:ecf8078bf531 130 }
andrewcrussell 1:ecf8078bf531 131 /*************** Volume IRQ ***********/
andrewcrussell 1:ecf8078bf531 132 void volume1() {
andrewcrussell 2:67e16df2c89a 133
andrewcrussell 1:ecf8078bf531 134 wait_ms(5); /* wait for contact bounce to subside */
andrewcrussell 1:ecf8078bf531 135 PortIn encoder(Port2, 48); /* extract data on mbed pins 21 and 22 - bit positions 8 and 16 on p2 */
andrewcrussell 1:ecf8078bf531 136 switch (encoder) {
andrewcrussell 1:ecf8078bf531 137 case 32:
andrewcrussell 1:ecf8078bf531 138 break;
andrewcrussell 1:ecf8078bf531 139 case 48:
andrewcrussell 1:ecf8078bf531 140 break;
andrewcrussell 1:ecf8078bf531 141
andrewcrussell 1:ecf8078bf531 142 case 0: {
andrewcrussell 1:ecf8078bf531 143 volume--;
andrewcrussell 1:ecf8078bf531 144 flag=9211;
andrewcrussell 1:ecf8078bf531 145 }
andrewcrussell 1:ecf8078bf531 146 break; /* rotary encoder was turned clockwise */
andrewcrussell 1:ecf8078bf531 147 case 16: {
andrewcrussell 1:ecf8078bf531 148 volume++;
andrewcrussell 1:ecf8078bf531 149 flag=9221;
andrewcrussell 1:ecf8078bf531 150 }
andrewcrussell 1:ecf8078bf531 151 break;
andrewcrussell 1:ecf8078bf531 152 }
andrewcrussell 1:ecf8078bf531 153 remcontoken=0;
andrewcrussell 1:ecf8078bf531 154 }
andrewcrussell 1:ecf8078bf531 155 /******************* volume control write routine **********************/
andrewcrussell 1:ecf8078bf531 156 /* this routine writes the volume control data out to the PGA2320 */
andrewcrussell 1:ecf8078bf531 157 void volumecontrol(void) {
andrewcrussell 1:ecf8078bf531 158 int lrvol =0; /* lrvol (i.e. left and right volume) is the concatenated left & right volume setting */
andrewcrussell 1:ecf8078bf531 159 int gain;
andrewcrussell 1:ecf8078bf531 160 int vol_shift_bit=0;
andrewcrussell 1:ecf8078bf531 161 int volshift=0;
andrewcrussell 1:ecf8078bf531 162 int voltemp=0;
andrewcrussell 1:ecf8078bf531 163 int SCOUNT=1;
andrewcrussell 1:ecf8078bf531 164 int k = 32768; /* k is now located at bit position 15 */
andrewcrussell 2:67e16df2c89a 165 //if the volume up/down comes in through the remote control, it comes directly here from the R/C
andrewcrussell 2:67e16df2c89a 166 //IRQ handler. If it comes in via the rotarty encoder, it skips this part
andrewcrussell 1:ecf8078bf531 167 if (remcontoken==1) { /* command came in through the IRC */
andrewcrussell 1:ecf8078bf531 168 if (flag==9221) {
andrewcrussell 2:67e16df2c89a 169 volume=volume+4; /* volume up and down is a bit quicker via the IRC */
andrewcrussell 1:ecf8078bf531 170 }
andrewcrussell 1:ecf8078bf531 171 if (flag==9211) {
andrewcrussell 2:67e16df2c89a 172 volume=volume-4;
andrewcrussell 1:ecf8078bf531 173 }
andrewcrussell 1:ecf8078bf531 174 }
andrewcrussell 2:67e16df2c89a 175 /******* check here that it is within range 0 to +255 ********/
andrewcrussell 2:67e16df2c89a 176 // entry point is HERE if coming in via rotary encoder
andrewcrussell 2:67e16df2c89a 177 if (volume>=222)
andrewcrussell 2:67e16df2c89a 178 volume=222;
andrewcrussell 1:ecf8078bf531 179 if (volume <=1) // check this - can it not be 0?
andrewcrussell 1:ecf8078bf531 180 volume=0;
andrewcrussell 1:ecf8078bf531 181 volume_slider(volume);
andrewcrussell 2:67e16df2c89a 182 gain= 31.5-(0.5*(255-volume));
andrewcrussell 2:67e16df2c89a 183 if (((gain >-10)&&(gain<10))==TRUE) {
andrewcrussell 2:67e16df2c89a 184 LCDSetRect(265,379,460,475,1,BLACK); //clear the volume area
andrewcrussell 2:67e16df2c89a 185 snprintf( temp_string, STR_LENGTH_1, " "); //flush the print area
andrewcrussell 2:67e16df2c89a 186 snprintf( temp_string, STR_LENGTH_1, "%+ddB",gain);
andrewcrussell 2:67e16df2c89a 187 }
andrewcrussell 2:67e16df2c89a 188 char temp_string[ STR_LENGTH ];
andrewcrussell 2:67e16df2c89a 189 snprintf( temp_string, STR_LENGTH, " "); //flush the print area
andrewcrussell 2:67e16df2c89a 190 snprintf( temp_string, STR_LENGTH, "%+ddB",gain);
andrewcrussell 2:67e16df2c89a 191 FontDrawString( temp_string, 185, 380, WHITE, BLACK, &Calibri72 );
andrewcrussell 1:ecf8078bf531 192
andrewcrussell 1:ecf8078bf531 193 /************************ Write the data out to the PGA2320 ************************/
andrewcrussell 1:ecf8078bf531 194 /* for the PGA2320, data is clocked out MSB first, starting with the Right channel */
andrewcrussell 2:67e16df2c89a 195
andrewcrussell 1:ecf8078bf531 196 volshift=volume;
andrewcrussell 1:ecf8078bf531 197 voltemp=volume; /* save volume and leave it untouched */
andrewcrussell 1:ecf8078bf531 198 lrvol = (voltemp<<8); /* volume value now occupies bits 8-16 with bits 0-7 filled with 0's */
andrewcrussell 1:ecf8078bf531 199 lrvol = (lrvol|volshift); /* now have a copy of volume in botton 8 LSB's - so 16 bits of data in total*/
andrewcrussell 1:ecf8078bf531 200 pga2320=LOW; /* make sure the PGA2320 is de-selected */
andrewcrussell 1:ecf8078bf531 201 RD=LOW; /* ASTROBE - we do NOT use STROBE when writing the volume to the PGA2320 */
andrewcrussell 1:ecf8078bf531 202 WR=LOW; /* MDATA in low state*/
andrewcrussell 1:ecf8078bf531 203 RS=HIGH; /* ACLK - it is now LOW on the isolated side*/
andrewcrussell 1:ecf8078bf531 204 SBUSON=HIGH; /* turn the SBUS on */
andrewcrussell 2:67e16df2c89a 205 wait_us(50); //was 50
andrewcrussell 1:ecf8078bf531 206 pga2320=HIGH; /* chip select the PGA2320-so it goes LOW on the analog board */
andrewcrussell 1:ecf8078bf531 207 do {
andrewcrussell 1:ecf8078bf531 208 vol_shift_bit = (lrvol&k); /* ADATA = the MSB (k=1) */
andrewcrussell 1:ecf8078bf531 209 WR=!vol_shift_bit; /* put the 1st bit to be written on the WR pin AFTER INVERTING IT */
andrewcrussell 2:67e16df2c89a 210 wait_us(10);
andrewcrussell 1:ecf8078bf531 211 RS=LOW; /* clock it out */
andrewcrussell 2:67e16df2c89a 212 wait_us(10);
andrewcrussell 1:ecf8078bf531 213 RS=HIGH;
andrewcrussell 1:ecf8078bf531 214 SCOUNT=SCOUNT+1; /* increment the bit counter */
andrewcrussell 1:ecf8078bf531 215 k=(k>>1); /* shift bit mask up one position towards the LSB */
andrewcrussell 1:ecf8078bf531 216 } while (SCOUNT<16); /* send all 16 bits for L & R channel */
andrewcrussell 2:67e16df2c89a 217 /* note that it is 15 bit positions and NOT 16! */
andrewcrussell 2:67e16df2c89a 218 wait_us(10);//was 10
andrewcrussell 1:ecf8078bf531 219 pga2320=LOW; /* deselect PGA2320 */
andrewcrussell 2:67e16df2c89a 220 wait_us(10); //was 10
andrewcrussell 1:ecf8078bf531 221 SBUSON=LOW;
andrewcrussell 1:ecf8078bf531 222 flag=0; /* clear the flag since the command is now completed */
andrewcrussell 1:ecf8078bf531 223 remcontoken=0; /* we have executed the request, now clear the token */
andrewcrussell 2:67e16df2c89a 224 wait_us(10); //was 20
andrewcrussell 2:67e16df2c89a 225
andrewcrussell 2:67e16df2c89a 226 }
andrewcrussell 1:ecf8078bf531 227 /*************** Serial bus routine for control relays and digital I/O ***************/
andrewcrussell 1:ecf8078bf531 228 /* this routine takes the 8 bit relay data and the 8 bit control data and joins them */
andrewcrussell 1:ecf8078bf531 229 /* and writes 16 bits out on the serial bus */
andrewcrussell 1:ecf8078bf531 230 /* it is called by the relay function or the control function */
andrewcrussell 1:ecf8078bf531 231
andrewcrussell 1:ecf8078bf531 232 void serialout(void) {
andrewcrussell 1:ecf8078bf531 233 unsigned int serialdata=0;/* the 16 bits of serial data to go out to the analog board - flush it so its clean */
andrewcrussell 1:ecf8078bf531 234 unsigned int shift_out_bit=0;
andrewcrussell 1:ecf8078bf531 235 long int stor_relay=0;
andrewcrussell 1:ecf8078bf531 236 int m=1;
andrewcrussell 1:ecf8078bf531 237 int SCOUNT=0;
andrewcrussell 1:ecf8078bf531 238
andrewcrussell 2:67e16df2c89a 239 __disable_irq(); /* disable Interrupts - no interference while we send the data out */
andrewcrussell 2:67e16df2c89a 240
andrewcrussell 1:ecf8078bf531 241 stor_relay=(255-inputrelay); /* get the complement */
andrewcrussell 1:ecf8078bf531 242 serialdata = (control | stor_relay);
andrewcrussell 1:ecf8078bf531 243
andrewcrussell 1:ecf8078bf531 244 RD=LOW; /* ASTROBE - it must be LOW on the analog board intitially */
andrewcrussell 1:ecf8078bf531 245 WR=HIGH; /* MDATA */
andrewcrussell 1:ecf8078bf531 246 RS=HIGH; /* ACLK - so the clock line on the analog board is now LOW*/
andrewcrussell 1:ecf8078bf531 247 SBUSON=HIGH; /* turn the SBUS on */
andrewcrussell 2:67e16df2c89a 248 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 249 do {
andrewcrussell 1:ecf8078bf531 250 shift_out_bit = (serialdata & m); /* ADATA = the LSB (k=1) */
andrewcrussell 1:ecf8078bf531 251 if (shift_out_bit!=0) { /* if it evaluates as TRUE, WR=HIGH */
andrewcrussell 1:ecf8078bf531 252 WR=1;
andrewcrussell 1:ecf8078bf531 253 } else { /* it must have evaluated as FALSE */
andrewcrussell 1:ecf8078bf531 254 WR=0;
andrewcrussell 1:ecf8078bf531 255 }
andrewcrussell 2:67e16df2c89a 256 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 257 RS=LOW; /* clock goes high on main board - data latches */
andrewcrussell 2:67e16df2c89a 258 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 259 RS=HIGH; /* clock goes low */
andrewcrussell 1:ecf8078bf531 260 SCOUNT++; /* increment the bit counter */
andrewcrussell 1:ecf8078bf531 261 m=(m<<1); /* shift bit mask up one position towards the MSB */
andrewcrussell 1:ecf8078bf531 262 } while (SCOUNT<16);
andrewcrussell 2:67e16df2c89a 263 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 264 RD=HIGH; /* Strobe the data into the A6821*/
andrewcrussell 2:67e16df2c89a 265 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 266 RD=LOW; /* Strobe now goes LOW again on the main board */
andrewcrussell 2:67e16df2c89a 267 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 268 SBUSON=LOW; /* remember to enable the outputs after intial set-up */
andrewcrussell 2:67e16df2c89a 269 wait_us(100); //was 100
andrewcrussell 1:ecf8078bf531 270 __enable_irq(); // Enable Interrupts
andrewcrussell 1:ecf8078bf531 271 }
andrewcrussell 1:ecf8078bf531 272 /******************************* Play ****************************/
andrewcrussell 1:ecf8078bf531 273 void play(void) {
andrewcrussell 2:67e16df2c89a 274 //myled=!myled;
andrewcrussell 1:ecf8078bf531 275 flag=0;
andrewcrussell 1:ecf8078bf531 276 remcontoken=0;
andrewcrussell 1:ecf8078bf531 277 }
andrewcrussell 1:ecf8078bf531 278 /******************************* Input Selector Encoder Routine ****************************/
andrewcrussell 1:ecf8078bf531 279 /* this function controls which relays are energized on the main analog board */
andrewcrussell 1:ecf8078bf531 280 /* It calls the serialout function to send the data */
andrewcrussell 1:ecf8078bf531 281
andrewcrussell 1:ecf8078bf531 282 void inputselect(void) {
andrewcrussell 1:ecf8078bf531 283
andrewcrussell 1:ecf8078bf531 284 int source=0; /* temporary storage */
andrewcrussell 1:ecf8078bf531 285 wait_ms(10); /*wait for contact bounce to subside */
andrewcrussell 1:ecf8078bf531 286 // __disable_irq(); // Disable Interrupts
andrewcrussell 1:ecf8078bf531 287
andrewcrussell 1:ecf8078bf531 288 if (remcontoken==0) { /* so it must have come in from the rotary encoder */
andrewcrussell 1:ecf8078bf531 289 PortIn select(Port2, 6); /* fetch data on mbed pins 24 and 25 - bit positions 2 and 4 on p2 */
andrewcrussell 1:ecf8078bf531 290 switch (select) {
andrewcrussell 1:ecf8078bf531 291 case 0:
andrewcrussell 1:ecf8078bf531 292 relay++;
andrewcrussell 1:ecf8078bf531 293 break; /* rotary encoder was turned clockwise */
andrewcrussell 1:ecf8078bf531 294 case 2:
andrewcrussell 1:ecf8078bf531 295 relay--;
andrewcrussell 1:ecf8078bf531 296 break; /* increment the selection */
andrewcrussell 1:ecf8078bf531 297
andrewcrussell 1:ecf8078bf531 298 case 4: {} break; /* fall through values - ignore */
andrewcrussell 1:ecf8078bf531 299 case 6: {} break;
andrewcrussell 1:ecf8078bf531 300 }
andrewcrussell 1:ecf8078bf531 301 } else {
andrewcrussell 1:ecf8078bf531 302 relay++; /* and here because it came in from the remote */
andrewcrussell 1:ecf8078bf531 303 } /* because it must have equaled 1 to have got here */
andrewcrussell 1:ecf8078bf531 304 /* because you can only go round select in one direction via the remote */
andrewcrussell 1:ecf8078bf531 305
andrewcrussell 1:ecf8078bf531 306 if (relay>=6) /* here we make sure the select knob rotates from 1-6 to again */
andrewcrussell 1:ecf8078bf531 307 relay=1;
andrewcrussell 1:ecf8078bf531 308 if (relay<=0)
andrewcrussell 1:ecf8078bf531 309 relay=5;
andrewcrussell 1:ecf8078bf531 310 /* set the correct value in the serial bit position */
andrewcrussell 1:ecf8078bf531 311 clear_input_select();
andrewcrussell 1:ecf8078bf531 312 switch (relay) {
andrewcrussell 1:ecf8078bf531 313 case 1:
andrewcrussell 1:ecf8078bf531 314 source=32;//~125;//~125;//~(2&127);
andrewcrussell 1:ecf8078bf531 315 AUX2(1);
andrewcrussell 1:ecf8078bf531 316 //printf("\n\rAux2");
andrewcrussell 1:ecf8078bf531 317 break; /* this is Aux2*/
andrewcrussell 1:ecf8078bf531 318 case 2:
andrewcrussell 1:ecf8078bf531 319 source=16;//~123;//~(4&127);
andrewcrussell 1:ecf8078bf531 320 AUX1(1);
andrewcrussell 1:ecf8078bf531 321 //printf("\n\raux1");
andrewcrussell 1:ecf8078bf531 322 break; /*aux1 */
andrewcrussell 1:ecf8078bf531 323 case 3:
andrewcrussell 1:ecf8078bf531 324 source=8;//~127;~(8&127);
andrewcrussell 1:ecf8078bf531 325 Recorder_d(1);
andrewcrussell 1:ecf8078bf531 326 //printf("\n\recorder");
andrewcrussell 1:ecf8078bf531 327
andrewcrussell 1:ecf8078bf531 328 break; /*recorder */
andrewcrussell 1:ecf8078bf531 329 case 4:
andrewcrussell 1:ecf8078bf531 330 source=4;//~111;//~(16&127);
andrewcrussell 1:ecf8078bf531 331 //printf("\n\rCD");
andrewcrussell 1:ecf8078bf531 332 //
andrewcrussell 1:ecf8078bf531 333 CD_d(1);
andrewcrussell 1:ecf8078bf531 334 break; /*CD*/
andrewcrussell 1:ecf8078bf531 335 case 5:
andrewcrussell 1:ecf8078bf531 336 source=2;;//~95;//~(32&127);
andrewcrussell 1:ecf8078bf531 337 //printf("\n\rphono");
andrewcrussell 1:ecf8078bf531 338 phono_d(1);
andrewcrussell 1:ecf8078bf531 339 break; /*phono*/
andrewcrussell 1:ecf8078bf531 340 }
andrewcrussell 1:ecf8078bf531 341
andrewcrussell 1:ecf8078bf531 342 inputrelay=(hpmutebit|mutebit|recloop1bit);/* save the non input select data */
andrewcrussell 1:ecf8078bf531 343
andrewcrussell 1:ecf8078bf531 344 inputrelay=(inputrelay&193); /*strip out the old input select, leaving HPMUTE, recloop1bit and mutebit intact */
andrewcrussell 1:ecf8078bf531 345
andrewcrussell 1:ecf8078bf531 346 inputrelay=(inputrelay|source); /* add in the new input selection back in*/
andrewcrussell 1:ecf8078bf531 347
andrewcrussell 1:ecf8078bf531 348 flag=0;
andrewcrussell 1:ecf8078bf531 349 remcontoken=0;
andrewcrussell 1:ecf8078bf531 350
andrewcrussell 1:ecf8078bf531 351 serialout(); /* send it out */
andrewcrussell 2:67e16df2c89a 352 // __enable_irq(); // Enable Interrupts
andrewcrussell 2:67e16df2c89a 353 }
andrewcrussell 2:67e16df2c89a 354 /*****************************************record loop ***********************************************/
andrewcrussell 2:67e16df2c89a 355 void recloop(void) {
andrewcrussell 2:67e16df2c89a 356
andrewcrussell 2:67e16df2c89a 357 if (recloop1bit==0) {//so it must have been OFF so we need to turn it on
andrewcrussell 2:67e16df2c89a 358 recloop1bit=64;
andrewcrussell 2:67e16df2c89a 359 record(1);
andrewcrussell 2:67e16df2c89a 360 inputrelay=(inputrelay|64);
andrewcrussell 2:67e16df2c89a 361 }
andrewcrussell 2:67e16df2c89a 362 else if (recloop1bit!=0) { // it was ON so turn it OFF
andrewcrussell 2:67e16df2c89a 363 recloop1bit=0;
andrewcrussell 2:67e16df2c89a 364 record(0);
andrewcrussell 2:67e16df2c89a 365 inputrelay=inputrelay & (~64);
andrewcrussell 2:67e16df2c89a 366 }
andrewcrussell 2:67e16df2c89a 367 flag=0;
andrewcrussell 2:67e16df2c89a 368 //remcontoken=0;
andrewcrussell 2:67e16df2c89a 369 serialout();
andrewcrussell 1:ecf8078bf531 370 }
andrewcrussell 1:ecf8078bf531 371 /**************************** output mute via front panel push button********************************/
andrewcrussell 1:ecf8078bf531 372 void mute_output(void) { /* this is the interrupt handler routine */
andrewcrussell 1:ecf8078bf531 373
andrewcrussell 2:67e16df2c89a 374 unsigned int timecountrec=0;
andrewcrussell 2:67e16df2c89a 375 //__disable_irq(); // Disable Interrupts
andrewcrussell 2:67e16df2c89a 376 wait_ms(10);
andrewcrussell 2:67e16df2c89a 377 do {
andrewcrussell 2:67e16df2c89a 378 timecountrec++;
andrewcrussell 2:67e16df2c89a 379 wait_us(10);
andrewcrussell 2:67e16df2c89a 380 if (timecountrec>110000)
andrewcrussell 2:67e16df2c89a 381 timecountrec=110000; //just make sure if the buttin is depressed for too long, it
andrewcrussell 2:67e16df2c89a 382 //record(1); // it does not wrap around bacj to 0 again
andrewcrussell 2:67e16df2c89a 383 } while (IPSELPB==0);
andrewcrussell 2:67e16df2c89a 384 //printf("timecountrec=%d\n\r",timecountrec);
andrewcrussell 2:67e16df2c89a 385 if (timecountrec>100000) {
andrewcrussell 2:67e16df2c89a 386 recloop();
andrewcrussell 2:67e16df2c89a 387 goto SKIP;
andrewcrussell 2:67e16df2c89a 388 }
andrewcrussell 1:ecf8078bf531 389 if (mutebit==0) { /* it must have been off */
andrewcrussell 2:67e16df2c89a 390 mutebit=128; //was 128 /* so turn it ON - this is a FLAG */
andrewcrussell 2:67e16df2c89a 391 inputrelay=(inputrelay|128); //was 128
andrewcrussell 1:ecf8078bf531 392 mute(0);
andrewcrussell 1:ecf8078bf531 393 }
andrewcrussell 1:ecf8078bf531 394 else if (mutebit==128) { /* it currently ON */
andrewcrussell 1:ecf8078bf531 395 mutebit=0; /* so turn the output OFF - this is a FLAG */
andrewcrussell 2:67e16df2c89a 396 inputrelay=(inputrelay&127); //so bit 128 is set to 0
andrewcrussell 1:ecf8078bf531 397 mute(1);
andrewcrussell 1:ecf8078bf531 398 }
andrewcrussell 2:67e16df2c89a 399 SKIP:
andrewcrussell 1:ecf8078bf531 400 flag=0;
andrewcrussell 1:ecf8078bf531 401 remcontoken=0;
andrewcrussell 2:67e16df2c89a 402 //__enable_irq(); // Enable Interrupts
andrewcrussell 1:ecf8078bf531 403 serialout();
andrewcrussell 1:ecf8078bf531 404
andrewcrussell 1:ecf8078bf531 405 }
andrewcrussell 1:ecf8078bf531 406 /**********************************initialize *****************************************/
andrewcrussell 1:ecf8078bf531 407 /* this routine sets up the pre-amp at initial power-up. all relays on the main board */
andrewcrussell 1:ecf8078bf531 408 /* are de-energized, volume is set to 0, display off, system in standby */
andrewcrussell 1:ecf8078bf531 409
andrewcrussell 1:ecf8078bf531 410 void initialize(void) {
andrewcrussell 1:ecf8078bf531 411
andrewcrussell 1:ecf8078bf531 412 int SCOUNT=0;
andrewcrussell 1:ecf8078bf531 413 int k=1; /*this is the bit place holder that gets shifted through the data to be sent */
andrewcrussell 1:ecf8078bf531 414 int flushit=0; /* flushit explicitly declared since we may want a setting other than all OFF */
andrewcrussell 1:ecf8078bf531 415 int shift_flush =0;
andrewcrussell 1:ecf8078bf531 416
andrewcrussell 1:ecf8078bf531 417 RD=LOW; /* ASTROBE */
andrewcrussell 1:ecf8078bf531 418 WR=LOW; /* MDATA */
andrewcrussell 1:ecf8078bf531 419 RS=LOW; /* ACLK */
andrewcrussell 1:ecf8078bf531 420 SBUSON=HIGH; /* turn the SBUS on */
andrewcrussell 1:ecf8078bf531 421 do {
andrewcrussell 1:ecf8078bf531 422 shift_flush=(flushit&k); /* ADATA = the LSB (k=1) */
andrewcrussell 1:ecf8078bf531 423 WR=shift_flush;
andrewcrussell 1:ecf8078bf531 424 wait_ms(1);
andrewcrussell 1:ecf8078bf531 425 RS=HIGH; /* clock it out */
andrewcrussell 1:ecf8078bf531 426 wait_ms(1);
andrewcrussell 1:ecf8078bf531 427 RS=LOW;
andrewcrussell 1:ecf8078bf531 428 SCOUNT=SCOUNT+1; /* increment the bit counter */
andrewcrussell 1:ecf8078bf531 429 k=(k<<1); /* shift bit mask up one position towards the MSB */
andrewcrussell 1:ecf8078bf531 430 } while (SCOUNT<8); /* counting starts from 0! */
andrewcrussell 1:ecf8078bf531 431 wait_ms(1);
andrewcrussell 1:ecf8078bf531 432 RD=HIGH; /* Strobe the data into the A6821*/
andrewcrussell 1:ecf8078bf531 433 wait_ms(1);
andrewcrussell 1:ecf8078bf531 434 RD=LOW; /* Strobe now goes HIGH again on the main board */
andrewcrussell 1:ecf8078bf531 435 wait_ms(1);
andrewcrussell 1:ecf8078bf531 436 SBUSON=LOW; /* remember to enable the outputs after intial set-up */
andrewcrussell 1:ecf8078bf531 437 power=0;
andrewcrussell 2:67e16df2c89a 438 wait_ms(10); //was 100
andrewcrussell 1:ecf8078bf531 439 }
andrewcrussell 1:ecf8078bf531 440 /******************** ON-OFF Push button input *******************************************/
andrewcrussell 2:67e16df2c89a 441 void power_on_off(void) {
andrewcrussell 2:67e16df2c89a 442 //
andrewcrussell 1:ecf8078bf531 443
andrewcrussell 2:67e16df2c89a 444 //int inputstate = 0; /* where we temporarily store the input relay status */
andrewcrussell 2:67e16df2c89a 445 //int b=5;
andrewcrussell 1:ecf8078bf531 446 //__disable_irq(); // Disable Interrupts
andrewcrussell 1:ecf8078bf531 447 //__enable_irq(); // Enable Interrupts
andrewcrussell 1:ecf8078bf531 448 wait_ms(10); /* debounce time NOTE IF ITS MUCH LONGER THAN 10mS THERE ARE RE-ENTRY PROBLEMS*/
andrewcrussell 2:67e16df2c89a 449
andrewcrussell 1:ecf8078bf531 450 if (power == 0) { /* it must have been off so turn it ON */
andrewcrussell 1:ecf8078bf531 451 //__disable_irq(); // Disable Interrupts
andrewcrussell 1:ecf8078bf531 452
andrewcrussell 1:ecf8078bf531 453 //Write_Command(DISON);
andrewcrussell 1:ecf8078bf531 454 //clear_to_color(BLACK); //clear the screen
andrewcrussell 1:ecf8078bf531 455 /* clean everything up first */
andrewcrussell 1:ecf8078bf531 456 inputrelay = 0; /* all input relays are DESELECTED */
andrewcrussell 1:ecf8078bf531 457 mute(1);
andrewcrussell 2:67e16df2c89a 458
andrewcrussell 2:67e16df2c89a 459 volume = 0; /* set the volume to 0 to make sure there are no blasts from the headphone or output */
andrewcrussell 2:67e16df2c89a 460 volumecontrol();
andrewcrussell 1:ecf8078bf531 461 control = 0;
andrewcrussell 2:67e16df2c89a 462 wait_ms(100); /* initial wait period after power on - lets relays and electronics settle */
andrewcrussell 1:ecf8078bf531 463 serialout();
andrewcrussell 1:ecf8078bf531 464
andrewcrussell 1:ecf8078bf531 465 NAOE = HIGH; /* enable outputs of A6281's */
andrewcrussell 2:67e16df2c89a 466 wait_ms(100);
andrewcrussell 1:ecf8078bf531 467 inputrelay = 4;//32; /* select CD input always on power up */
andrewcrussell 1:ecf8078bf531 468 CD_d(1);
andrewcrussell 1:ecf8078bf531 469 control = 33280; /* power to main board on and LCD brightness set to 50% */
andrewcrussell 1:ecf8078bf531 470 serialout();
andrewcrussell 1:ecf8078bf531 471
andrewcrussell 1:ecf8078bf531 472 wait(2);
andrewcrussell 1:ecf8078bf531 473 inputrelay = 5;// 161; /* unmute the headphone amp */
andrewcrussell 1:ecf8078bf531 474 control = 33280; /* stays the same power to main board on and LCD brightness set to 50% */
andrewcrussell 1:ecf8078bf531 475 serialout();
andrewcrussell 1:ecf8078bf531 476
andrewcrussell 1:ecf8078bf531 477 wait(2); /* let the power amp settle */
andrewcrussell 1:ecf8078bf531 478 control=35328; /* turn power amp on */
andrewcrussell 2:67e16df2c89a 479 pwramp(1);
andrewcrussell 2:67e16df2c89a 480 inputrelay = 133; /* unmute the pre-amp output */
andrewcrussell 1:ecf8078bf531 481 mute(0);
andrewcrussell 1:ecf8078bf531 482 serialout();
andrewcrussell 1:ecf8078bf531 483
andrewcrussell 1:ecf8078bf531 484 mutebit = 128; /* set to 1 to turn it ON - THIS IS A FLAG!! */
andrewcrussell 1:ecf8078bf531 485 hpmutebit = 1; /* set to 127 to turn it ON - THIS IS THE FLAG!!*/
andrewcrussell 1:ecf8078bf531 486 //serialout();
andrewcrussell 1:ecf8078bf531 487 power = 64; /* this is the power ON/OFF FLAG */
andrewcrussell 2:67e16df2c89a 488 volume=95;
andrewcrussell 1:ecf8078bf531 489 volumecontrol();
andrewcrussell 2:67e16df2c89a 490
andrewcrussell 1:ecf8078bf531 491 /* re-enable the mute, volumecontrol and input selection interrupts */
andrewcrussell 1:ecf8078bf531 492 wait_ms(1);
andrewcrussell 1:ecf8078bf531 493
andrewcrussell 1:ecf8078bf531 494 mutesw.fall(&mute1);
andrewcrussell 1:ecf8078bf531 495 volumein.fall(&volume1);
andrewcrussell 1:ecf8078bf531 496 inputsel.fall(&inputsel1);
andrewcrussell 1:ecf8078bf531 497 // __enable_irq(); // Enable Interrupts
andrewcrussell 1:ecf8078bf531 498 }
andrewcrussell 1:ecf8078bf531 499
andrewcrussell 1:ecf8078bf531 500 else if (power == 64) { /* it currently ON, so turn it OFF */
andrewcrussell 1:ecf8078bf531 501 /* disable the mute, columecontrol and input selection interrupts - leave power ON/OFF enabled though */
andrewcrussell 1:ecf8078bf531 502 // __disable_irq(); // Disable Interrupts
andrewcrussell 2:67e16df2c89a 503 volume = 0;
andrewcrussell 2:67e16df2c89a 504 volumecontrol();
andrewcrussell 1:ecf8078bf531 505 mutesw.fall(NULL);
andrewcrussell 1:ecf8078bf531 506 volumein.fall(NULL);
andrewcrussell 1:ecf8078bf531 507 inputsel.fall(NULL);
andrewcrussell 1:ecf8078bf531 508 control= (control & 62332); /*turn power amp off */
andrewcrussell 2:67e16df2c89a 509 pwramp(0);
andrewcrussell 1:ecf8078bf531 510 serialout();
andrewcrussell 1:ecf8078bf531 511 wait(2); /* wait for the power-amp to power down and spkr relay to open */
andrewcrussell 1:ecf8078bf531 512 inputrelay = (inputrelay & 126); /* mute the pre-amp output */
andrewcrussell 1:ecf8078bf531 513 serialout(); /* note we did not change anything on the control side */
andrewcrussell 1:ecf8078bf531 514 wait(1);
andrewcrussell 1:ecf8078bf531 515 control=(control & 768); /* turn the display off and set the zero loop gain off */
andrewcrussell 1:ecf8078bf531 516 inputrelay = (inputrelay & 127); /* mute headphone output */
andrewcrussell 1:ecf8078bf531 517 serialout();
andrewcrussell 1:ecf8078bf531 518 wait(1);
andrewcrussell 1:ecf8078bf531 519 /*here we flush the A6821 registers */
andrewcrussell 1:ecf8078bf531 520 control = 0; /* turn everthing off */
andrewcrussell 1:ecf8078bf531 521 inputrelay = 0;
andrewcrussell 1:ecf8078bf531 522 serialout();
andrewcrussell 1:ecf8078bf531 523 wait(1);
andrewcrussell 1:ecf8078bf531 524 NAOE=LOW; /* disable the A6281's */
andrewcrussell 1:ecf8078bf531 525
andrewcrussell 1:ecf8078bf531 526 mutebit = 0; /* set to 1 to turn it ON - this is a FLAG */
andrewcrussell 1:ecf8078bf531 527 hpmutebit = 128; /* set to 127 to turn it ON - this is a FLAG */
andrewcrussell 1:ecf8078bf531 528 power = 0; /* this is the power FLAG */
andrewcrussell 1:ecf8078bf531 529 //Write_Command(DISOFF);
andrewcrussell 1:ecf8078bf531 530 //clear_to_color(BLACK); //clear the screen
andrewcrussell 1:ecf8078bf531 531
andrewcrussell 1:ecf8078bf531 532 //__enable_irq(); // Enable Interrupts again
andrewcrussell 1:ecf8078bf531 533 }
andrewcrussell 1:ecf8078bf531 534 flag = 0;
andrewcrussell 1:ecf8078bf531 535 remcontoken = 0;
andrewcrussell 1:ecf8078bf531 536 }
andrewcrussell 2:67e16df2c89a 537 /******************** backlight controller *****************************************/
andrewcrussell 2:67e16df2c89a 538 void backlight (void) {
andrewcrussell 1:ecf8078bf531 539
andrewcrussell 2:67e16df2c89a 540 float loglight;
andrewcrussell 2:67e16df2c89a 541 int lightadjust;
andrewcrussell 2:67e16df2c89a 542
andrewcrussell 2:67e16df2c89a 543 lightsensor();
andrewcrussell 2:67e16df2c89a 544 //loglight = (lightlevel * lightlevel) * 14.0 + 1.0;
andrewcrussell 2:67e16df2c89a 545 loglight = (lightlevel * 14)+1;
andrewcrussell 2:67e16df2c89a 546 lightadjust = ((int)loglight) << 12;
andrewcrussell 2:67e16df2c89a 547 control=(control & stripbacklight)|lightadjust;
andrewcrussell 2:67e16df2c89a 548 serialout();
andrewcrussell 2:67e16df2c89a 549 //printf("%d\n\r",control);
andrewcrussell 2:67e16df2c89a 550 }
andrewcrussell 1:ecf8078bf531 551 /******************** Test Mode Pushbutton input *******************************************/
andrewcrussell 1:ecf8078bf531 552 /* in this mode, both volume and select pushbuttons must be depressed for 5 seconds */
andrewcrussell 1:ecf8078bf531 553 /* the pre-amp then enters the test mode where all the relays are cycled continuosly */
andrewcrussell 1:ecf8078bf531 554 /* and the volume is ramped up and down. To exit, depress any push button. */
andrewcrussell 1:ecf8078bf531 555
andrewcrussell 1:ecf8078bf531 556 /**********************************main program*****************************************/
andrewcrussell 1:ecf8078bf531 557 int main () {
bf1891 3:92845c139aca 558 pc.baud(38400);
bf1891 3:92845c139aca 559 pc.printf("Hello World!\n\r");
andrewcrussell 1:ecf8078bf531 560 int l=0;
andrewcrussell 2:67e16df2c89a 561 //int loopcnt=0;
andrewcrussell 1:ecf8078bf531 562 __disable_irq(); // Disable Interrupts
andrewcrussell 1:ecf8078bf531 563 NAOE=LOW; // make sure the A6821's are disabled
andrewcrussell 1:ecf8078bf531 564 Init_SSD1963(); // set up he graphics controller
andrewcrussell 2:67e16df2c89a 565 Write_Command(DISOFF); // make sure the display is off while we set it up
andrewcrussell 1:ecf8078bf531 566 clear_to_color(BLACK); //clear the screen
andrewcrussell 1:ecf8078bf531 567 wait_ms(5);
andrewcrussell 1:ecf8078bf531 568 initialize(); // call the SBUS routine to clean things up
andrewcrussell 1:ecf8078bf531 569 powersw.fall(&power1);
andrewcrussell 1:ecf8078bf531 570 Serial remote(NC, p27);
andrewcrussell 1:ecf8078bf531 571 remote.baud(1200);
andrewcrussell 1:ecf8078bf531 572 remote.format(8, Serial::None, 1);
andrewcrussell 1:ecf8078bf531 573 remote.attach(&remotecontrol); /* set up serial port via USB connector */
andrewcrussell 1:ecf8078bf531 574 __enable_irq(); // Enable Interrupts
andrewcrussell 1:ecf8078bf531 575 wait_us(10);
andrewcrussell 1:ecf8078bf531 576
andrewcrussell 1:ecf8078bf531 577 /**************************************************************************************/
andrewcrussell 1:ecf8078bf531 578 // graphics set up
andrewcrussell 1:ecf8078bf531 579 // sett up graphics to write the data
andrewcrussell 1:ecf8078bf531 580 FontDrawInit();
andrewcrussell 1:ecf8078bf531 581 FontDraw_SetInterCharSpace( 0 );
andrewcrussell 1:ecf8078bf531 582 FontDraw_SetForegroundColor(WHITE);
andrewcrussell 1:ecf8078bf531 583 FontDraw_SetBackgroundColor(BLACK);
andrewcrussell 1:ecf8078bf531 584 FontDraw_SetFont(Calibri28);
andrewcrussell 2:67e16df2c89a 585 //big_button();
andrewcrussell 1:ecf8078bf531 586 Control_buttons();
andrewcrussell 1:ecf8078bf531 587 input_buttons();
andrewcrussell 1:ecf8078bf531 588 slider_bar();
andrewcrussell 2:67e16df2c89a 589 Write_Command(DISON);
andrewcrussell 2:67e16df2c89a 590
andrewcrussell 1:ecf8078bf531 591 /************************ this is the main operating loop ************************/
andrewcrussell 1:ecf8078bf531 592
andrewcrussell 1:ecf8078bf531 593 LOOP:
andrewcrussell 2:67e16df2c89a 594 //if ((flag>=9000)&&(flag<=9999)){
andrewcrussell 2:67e16df2c89a 595 //printf("%d\n\r",flag);
andrewcrussell 2:67e16df2c89a 596 //__disable_irq(); // Disable Interrupts
andrewcrussell 2:67e16df2c89a 597 //__enable_irq(); // Enable Interrupts
andrewcrussell 2:67e16df2c89a 598 if (flag!=0) { //so assume it lies between 9000 and 9999
andrewcrussell 1:ecf8078bf531 599 switch (flag) {
andrewcrussell 1:ecf8078bf531 600
andrewcrussell 1:ecf8078bf531 601 case 9211:
andrewcrussell 1:ecf8078bf531 602 volumecontrol();
andrewcrussell 1:ecf8078bf531 603 break; /* volume UP */
andrewcrussell 1:ecf8078bf531 604 case 9221:
andrewcrussell 1:ecf8078bf531 605 volumecontrol();
andrewcrussell 1:ecf8078bf531 606 break; /* volume DOWN */
andrewcrussell 1:ecf8078bf531 607 case 9231:
andrewcrussell 1:ecf8078bf531 608 inputselect();
andrewcrussell 1:ecf8078bf531 609 break; /* Input Select */
andrewcrussell 1:ecf8078bf531 610 case 9241:
andrewcrussell 1:ecf8078bf531 611 mute_output();
andrewcrussell 1:ecf8078bf531 612 break; /* Mute */
andrewcrussell 1:ecf8078bf531 613 case 9251:
andrewcrussell 1:ecf8078bf531 614 play();
andrewcrussell 1:ecf8078bf531 615 break; /* Play */
andrewcrussell 1:ecf8078bf531 616 case 9261:
andrewcrussell 1:ecf8078bf531 617 power_on_off();
andrewcrussell 1:ecf8078bf531 618 break; /* power ON/OFF */
andrewcrussell 2:67e16df2c89a 619 //case 9200:
andrewcrussell 2:67e16df2c89a 620 //recloop();
andrewcrussell 2:67e16df2c89a 621 }
andrewcrussell 2:67e16df2c89a 622 }
andrewcrussell 2:67e16df2c89a 623
andrewcrussell 2:67e16df2c89a 624 myled=!myled;
andrewcrussell 2:67e16df2c89a 625 __disable_irq(); // Disable Interrupts - this forces us to wait here for 10mS
andrewcrussell 1:ecf8078bf531 626 flag=0; /* flush the flag since we finished the task */
andrewcrussell 2:67e16df2c89a 627 wait_ms(10); //
andrewcrussell 2:67e16df2c89a 628 __enable_irq(); // Enable Interrupts
andrewcrussell 2:67e16df2c89a 629 backlight();
andrewcrussell 2:67e16df2c89a 630 halt(); /* shut processor down and wait for interrupt */
andrewcrussell 2:67e16df2c89a 631 myled=!myled;
andrewcrussell 1:ecf8078bf531 632 goto LOOP;
andrewcrussell 1:ecf8078bf531 633 }