Jubeat (ユビート Yubīto?), stylized as jubeat, is a series of arcade music video games developed by Konami Computer Entertainment Japan, and is a part of Konami's Bemani line of music video games. The series uses an arrangement of 16 buttons in a 4x4 grid for gameplay, a grid also used for the displaying of cues and part of the user interface.

Dependencies:   4DGL-uLCD-SE SDFileSystem TextLCD mbed-rtos mbed wave_player

Fork of ECE4180_Lab4 by Zhihan Jiang

Committer:
ToHellWithGeorgi
Date:
Wed Mar 16 13:38:50 2016 +0000
Revision:
0:c3c8793d0091
ECE 4180 jubeat;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ToHellWithGeorgi 0:c3c8793d0091 1 #include "VS1002.h"
ToHellWithGeorgi 0:c3c8793d0091 2 #include "mbed.h"
ToHellWithGeorgi 0:c3c8793d0091 3 #include "SDFileSystem.h"
ToHellWithGeorgi 0:c3c8793d0091 4
ToHellWithGeorgi 0:c3c8793d0091 5 //Serial pc(USBTX, USBRX);
ToHellWithGeorgi 0:c3c8793d0091 6 //TextLCD lcd(p30, p29, p17, p18, p19, p20);
ToHellWithGeorgi 0:c3c8793d0091 7
ToHellWithGeorgi 0:c3c8793d0091 8 /* ==================================================================
ToHellWithGeorgi 0:c3c8793d0091 9 * Constructor
ToHellWithGeorgi 0:c3c8793d0091 10 * =================================================================*/
ToHellWithGeorgi 0:c3c8793d0091 11
ToHellWithGeorgi 0:c3c8793d0091 12 VS1002::VS1002(PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName dreq, PinName dcs, PinName vol)
ToHellWithGeorgi 0:c3c8793d0091 13 : _sd(mmosi, mmiso, ssck, ccs, name), _spi(mosi, miso, sck), _CS(cs), _RST(rst), _DREQ(dreq), _DCS(dcs), _VOL(vol) {
ToHellWithGeorgi 0:c3c8793d0091 14
ToHellWithGeorgi 0:c3c8793d0091 15 }
ToHellWithGeorgi 0:c3c8793d0091 16
ToHellWithGeorgi 0:c3c8793d0091 17 /*===================================================================
ToHellWithGeorgi 0:c3c8793d0091 18 * Functions
ToHellWithGeorgi 0:c3c8793d0091 19 *==================================================================*/
ToHellWithGeorgi 0:c3c8793d0091 20
ToHellWithGeorgi 0:c3c8793d0091 21 void VS1002::cs_low(void)
ToHellWithGeorgi 0:c3c8793d0091 22 {
ToHellWithGeorgi 0:c3c8793d0091 23 _CS = 0;
ToHellWithGeorgi 0:c3c8793d0091 24 }
ToHellWithGeorgi 0:c3c8793d0091 25 void VS1002::cs_high(void)
ToHellWithGeorgi 0:c3c8793d0091 26 {
ToHellWithGeorgi 0:c3c8793d0091 27 _CS = 1;
ToHellWithGeorgi 0:c3c8793d0091 28 }
ToHellWithGeorgi 0:c3c8793d0091 29 void VS1002::dcs_low(void)
ToHellWithGeorgi 0:c3c8793d0091 30 {
ToHellWithGeorgi 0:c3c8793d0091 31 _DCS = 0;
ToHellWithGeorgi 0:c3c8793d0091 32 }
ToHellWithGeorgi 0:c3c8793d0091 33 void VS1002::dcs_high(void)
ToHellWithGeorgi 0:c3c8793d0091 34 {
ToHellWithGeorgi 0:c3c8793d0091 35 _DCS = 1;
ToHellWithGeorgi 0:c3c8793d0091 36 }
ToHellWithGeorgi 0:c3c8793d0091 37 void VS1002::sci_en(void) //SCI enable
ToHellWithGeorgi 0:c3c8793d0091 38 {
ToHellWithGeorgi 0:c3c8793d0091 39 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 40 dcs_high();
ToHellWithGeorgi 0:c3c8793d0091 41 cs_low();
ToHellWithGeorgi 0:c3c8793d0091 42 }
ToHellWithGeorgi 0:c3c8793d0091 43 void VS1002::sci_dis(void) //SCI disable
ToHellWithGeorgi 0:c3c8793d0091 44 {
ToHellWithGeorgi 0:c3c8793d0091 45 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 46 }
ToHellWithGeorgi 0:c3c8793d0091 47 void VS1002::sdi_en(void) //SDI enable
ToHellWithGeorgi 0:c3c8793d0091 48 {
ToHellWithGeorgi 0:c3c8793d0091 49 dcs_high();
ToHellWithGeorgi 0:c3c8793d0091 50 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 51 dcs_low();
ToHellWithGeorgi 0:c3c8793d0091 52 }
ToHellWithGeorgi 0:c3c8793d0091 53 void VS1002::sdi_dis(void) //SDI disable
ToHellWithGeorgi 0:c3c8793d0091 54 {
ToHellWithGeorgi 0:c3c8793d0091 55 dcs_high();
ToHellWithGeorgi 0:c3c8793d0091 56 }
ToHellWithGeorgi 0:c3c8793d0091 57 void VS1002::reset(void) //hardware reset
ToHellWithGeorgi 0:c3c8793d0091 58 {
ToHellWithGeorgi 0:c3c8793d0091 59 wait(0.01);
ToHellWithGeorgi 0:c3c8793d0091 60 _RST = 0;
ToHellWithGeorgi 0:c3c8793d0091 61 wait(0.01);
ToHellWithGeorgi 0:c3c8793d0091 62 _RST = 1;
ToHellWithGeorgi 0:c3c8793d0091 63 wait(0.10);
ToHellWithGeorgi 0:c3c8793d0091 64 }
ToHellWithGeorgi 0:c3c8793d0091 65 void VS1002::power_down(void) //hardware and software reset
ToHellWithGeorgi 0:c3c8793d0091 66 {
ToHellWithGeorgi 0:c3c8793d0091 67 cs_low();
ToHellWithGeorgi 0:c3c8793d0091 68 reset();
ToHellWithGeorgi 0:c3c8793d0091 69 sci_write(0x00, SM_PDOWN);
ToHellWithGeorgi 0:c3c8793d0091 70 wait(0.01);
ToHellWithGeorgi 0:c3c8793d0091 71 reset();
ToHellWithGeorgi 0:c3c8793d0091 72 }
ToHellWithGeorgi 0:c3c8793d0091 73 void VS1002::sci_initialise(void)
ToHellWithGeorgi 0:c3c8793d0091 74 {
ToHellWithGeorgi 0:c3c8793d0091 75 _RST = 1; //no reset
ToHellWithGeorgi 0:c3c8793d0091 76 _spi.format(8,0); //spi 8bit interface, steady state low
ToHellWithGeorgi 0:c3c8793d0091 77 _spi.frequency(1000000); //rising edge data record, freq. 1Mhz
ToHellWithGeorgi 0:c3c8793d0091 78
ToHellWithGeorgi 0:c3c8793d0091 79 cs_low();
ToHellWithGeorgi 0:c3c8793d0091 80 for(int i=0; i<4; i++)
ToHellWithGeorgi 0:c3c8793d0091 81 {
ToHellWithGeorgi 0:c3c8793d0091 82 _spi.write(0xFF); //clock the chip a bit
ToHellWithGeorgi 0:c3c8793d0091 83 }
ToHellWithGeorgi 0:c3c8793d0091 84 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 85 dcs_high();
ToHellWithGeorgi 0:c3c8793d0091 86 wait_us(5);
ToHellWithGeorgi 0:c3c8793d0091 87 }
ToHellWithGeorgi 0:c3c8793d0091 88 void VS1002::sdi_initialise(void)
ToHellWithGeorgi 0:c3c8793d0091 89 {
ToHellWithGeorgi 0:c3c8793d0091 90 _spi.format(8,0);
ToHellWithGeorgi 0:c3c8793d0091 91 _spi.frequency(7000000); //set to 7MHz
ToHellWithGeorgi 0:c3c8793d0091 92
ToHellWithGeorgi 0:c3c8793d0091 93 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 94 dcs_high();
ToHellWithGeorgi 0:c3c8793d0091 95 }
ToHellWithGeorgi 0:c3c8793d0091 96 void VS1002::sci_write(unsigned char address, unsigned short int data)
ToHellWithGeorgi 0:c3c8793d0091 97 {
ToHellWithGeorgi 0:c3c8793d0091 98 sci_en(); //enables SCI/disables SDI
ToHellWithGeorgi 0:c3c8793d0091 99
ToHellWithGeorgi 0:c3c8793d0091 100 while(!_DREQ); //wait unitl data request is high
ToHellWithGeorgi 0:c3c8793d0091 101 _spi.write(0x02); //SCI write
ToHellWithGeorgi 0:c3c8793d0091 102 _spi.write(address); //register address
ToHellWithGeorgi 0:c3c8793d0091 103 _spi.write((data >> 8) & 0xFF); //write out first half of data word
ToHellWithGeorgi 0:c3c8793d0091 104 _spi.write(data & 0xFF); //write out second half of data word
ToHellWithGeorgi 0:c3c8793d0091 105
ToHellWithGeorgi 0:c3c8793d0091 106 sci_dis(); //enables SDI/disables SCI
ToHellWithGeorgi 0:c3c8793d0091 107 wait_us(5);
ToHellWithGeorgi 0:c3c8793d0091 108 }
ToHellWithGeorgi 0:c3c8793d0091 109 void VS1002::sdi_write(unsigned char datum)
ToHellWithGeorgi 0:c3c8793d0091 110 {
ToHellWithGeorgi 0:c3c8793d0091 111 sdi_en();
ToHellWithGeorgi 0:c3c8793d0091 112
ToHellWithGeorgi 0:c3c8793d0091 113 while(!_DREQ);
ToHellWithGeorgi 0:c3c8793d0091 114 _spi.write(datum);
ToHellWithGeorgi 0:c3c8793d0091 115
ToHellWithGeorgi 0:c3c8793d0091 116 sci_dis();
ToHellWithGeorgi 0:c3c8793d0091 117 }
ToHellWithGeorgi 0:c3c8793d0091 118 unsigned short int VS1002::read(unsigned short int address)
ToHellWithGeorgi 0:c3c8793d0091 119 {
ToHellWithGeorgi 0:c3c8793d0091 120 cs_low(); //enables SCI/disables SDI
ToHellWithGeorgi 0:c3c8793d0091 121
ToHellWithGeorgi 0:c3c8793d0091 122 while(!_DREQ); //wait unitl data request is high
ToHellWithGeorgi 0:c3c8793d0091 123 _spi.write(0x03); //SCI write
ToHellWithGeorgi 0:c3c8793d0091 124 _spi.write(address); //register address
ToHellWithGeorgi 0:c3c8793d0091 125 unsigned short int received = _spi.write(0x00); //write out dummy byte
ToHellWithGeorgi 0:c3c8793d0091 126 received <<= 8;
ToHellWithGeorgi 0:c3c8793d0091 127 received += _spi.write(0x00); //write out dummy byte
ToHellWithGeorgi 0:c3c8793d0091 128
ToHellWithGeorgi 0:c3c8793d0091 129 cs_high(); //enables SDI/disables SCI
ToHellWithGeorgi 0:c3c8793d0091 130
ToHellWithGeorgi 0:c3c8793d0091 131 return received; //return received word
ToHellWithGeorgi 0:c3c8793d0091 132 }
ToHellWithGeorgi 0:c3c8793d0091 133 void VS1002::sine_test_activate(unsigned char wave)
ToHellWithGeorgi 0:c3c8793d0091 134 {
ToHellWithGeorgi 0:c3c8793d0091 135 cs_high(); //enables SDI/disables SCI
ToHellWithGeorgi 0:c3c8793d0091 136
ToHellWithGeorgi 0:c3c8793d0091 137 while(!_DREQ); //wait unitl data request is high
ToHellWithGeorgi 0:c3c8793d0091 138 _spi.write(0x53); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 139 _spi.write(0xEF); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 140 _spi.write(0x6E); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 141 _spi.write(wave); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 142 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 143 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 144 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 145 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 146
ToHellWithGeorgi 0:c3c8793d0091 147 cs_low(); //enables SCI/disables SDI
ToHellWithGeorgi 0:c3c8793d0091 148 }
ToHellWithGeorgi 0:c3c8793d0091 149 void VS1002::sine_test_deactivate(void)
ToHellWithGeorgi 0:c3c8793d0091 150 {
ToHellWithGeorgi 0:c3c8793d0091 151 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 152
ToHellWithGeorgi 0:c3c8793d0091 153 while(!_DREQ);
ToHellWithGeorgi 0:c3c8793d0091 154 _spi.write(0x45); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 155 _spi.write(0x78); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 156 _spi.write(0x69); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 157 _spi.write(0x74); //SDI write
ToHellWithGeorgi 0:c3c8793d0091 158 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 159 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 160 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 161 _spi.write(0x00); //filler byte
ToHellWithGeorgi 0:c3c8793d0091 162 }
ToHellWithGeorgi 0:c3c8793d0091 163
ToHellWithGeorgi 0:c3c8793d0091 164
ToHellWithGeorgi 0:c3c8793d0091 165 void VS1002::volume(signed int left, signed int right)
ToHellWithGeorgi 0:c3c8793d0091 166 {
ToHellWithGeorgi 0:c3c8793d0091 167 while(_DREQ == 0);
ToHellWithGeorgi 0:c3c8793d0091 168
ToHellWithGeorgi 0:c3c8793d0091 169 unsigned short int _left = -left; //convert the decibel values into a format
ToHellWithGeorgi 0:c3c8793d0091 170 unsigned short int _right = -right; //readable by the chip cf. datasheet p.32 subsection 8.6.11
ToHellWithGeorgi 0:c3c8793d0091 171 _left *= 2;
ToHellWithGeorgi 0:c3c8793d0091 172 _right *= 2;
ToHellWithGeorgi 0:c3c8793d0091 173 unsigned short int attenuation = ((256 * _left) + _right);
ToHellWithGeorgi 0:c3c8793d0091 174 cs_low();
ToHellWithGeorgi 0:c3c8793d0091 175 sci_write(0x0B, attenuation); //writeout these values
ToHellWithGeorgi 0:c3c8793d0091 176 cs_high();
ToHellWithGeorgi 0:c3c8793d0091 177 }
ToHellWithGeorgi 0:c3c8793d0091 178
ToHellWithGeorgi 0:c3c8793d0091 179 void VS1002::play_song(int song_number)
ToHellWithGeorgi 0:c3c8793d0091 180 {
ToHellWithGeorgi 0:c3c8793d0091 181 /*====== Song Select ======*/
ToHellWithGeorgi 0:c3c8793d0091 182
ToHellWithGeorgi 0:c3c8793d0091 183 char str[16] = "/sd/music/"; //folder where the songs are located
ToHellWithGeorgi 0:c3c8793d0091 184 sprintf(str+10,"%d",song_number); //appending song number to path of the file
ToHellWithGeorgi 0:c3c8793d0091 185 strcat(str,".mp3"); //appending .mp3 to file name
ToHellWithGeorgi 0:c3c8793d0091 186 FILE *song;
ToHellWithGeorgi 0:c3c8793d0091 187 //pc.printf("%s",str);
ToHellWithGeorgi 0:c3c8793d0091 188 unsigned char array[512]; //array for reading data from file
ToHellWithGeorgi 0:c3c8793d0091 189 bool play_new=false; // Variable to see if new_song has be assigned or not
ToHellWithGeorgi 0:c3c8793d0091 190
ToHellWithGeorgi 0:c3c8793d0091 191 song = fopen(str, "r"); // Open the music file in read mode
ToHellWithGeorgi 0:c3c8793d0091 192 //pc.printf("end reading music");
ToHellWithGeorgi 0:c3c8793d0091 193
ToHellWithGeorgi 0:c3c8793d0091 194 /* Printing to LCD the present status */
ToHellWithGeorgi 0:c3c8793d0091 195 // lcd.cls();
ToHellWithGeorgi 0:c3c8793d0091 196 if(pause)
ToHellWithGeorgi 0:c3c8793d0091 197 // lcd.printf("Paused ");
ToHellWithGeorgi 0:c3c8793d0091 198 if(mute)
ToHellWithGeorgi 0:c3c8793d0091 199 // lcd.printf("Muted");
ToHellWithGeorgi 0:c3c8793d0091 200 if(!mute && !pause)
ToHellWithGeorgi 0:c3c8793d0091 201 // lcd.printf("Playing");
ToHellWithGeorgi 0:c3c8793d0091 202
ToHellWithGeorgi 0:c3c8793d0091 203 //lcd.printf("\n %d %s",new_song_number,song_name[new_song_number-1]);
ToHellWithGeorgi 0:c3c8793d0091 204
ToHellWithGeorgi 0:c3c8793d0091 205 if(!song)
ToHellWithGeorgi 0:c3c8793d0091 206 {
ToHellWithGeorgi 0:c3c8793d0091 207 // lcd.printf("\n \n Error!!");
ToHellWithGeorgi 0:c3c8793d0091 208 exit(1);
ToHellWithGeorgi 0:c3c8793d0091 209 }
ToHellWithGeorgi 0:c3c8793d0091 210 while(!feof(song))
ToHellWithGeorgi 0:c3c8793d0091 211 {
ToHellWithGeorgi 0:c3c8793d0091 212 if(!pause)
ToHellWithGeorgi 0:c3c8793d0091 213 {
ToHellWithGeorgi 0:c3c8793d0091 214
ToHellWithGeorgi 0:c3c8793d0091 215 fread(&array, 1, 512, song);
ToHellWithGeorgi 0:c3c8793d0091 216 for(int i=0; i<512; i++)
ToHellWithGeorgi 0:c3c8793d0091 217 {
ToHellWithGeorgi 0:c3c8793d0091 218 sdi_write(array[i]);
ToHellWithGeorgi 0:c3c8793d0091 219 }
ToHellWithGeorgi 0:c3c8793d0091 220 volume(volume_set,volume_set);
ToHellWithGeorgi 0:c3c8793d0091 221 }
ToHellWithGeorgi 0:c3c8793d0091 222 if(new_song_number!=song_number)
ToHellWithGeorgi 0:c3c8793d0091 223 {
ToHellWithGeorgi 0:c3c8793d0091 224 play_new=true;
ToHellWithGeorgi 0:c3c8793d0091 225 break;
ToHellWithGeorgi 0:c3c8793d0091 226 }
ToHellWithGeorgi 0:c3c8793d0091 227
ToHellWithGeorgi 0:c3c8793d0091 228
ToHellWithGeorgi 0:c3c8793d0091 229 }
ToHellWithGeorgi 0:c3c8793d0091 230
ToHellWithGeorgi 0:c3c8793d0091 231 fclose(song); //close the file
ToHellWithGeorgi 0:c3c8793d0091 232
ToHellWithGeorgi 0:c3c8793d0091 233 if(!play_new)
ToHellWithGeorgi 0:c3c8793d0091 234 {
ToHellWithGeorgi 0:c3c8793d0091 235 new_song_number+=1; // Goto Next song on completion of one song
ToHellWithGeorgi 0:c3c8793d0091 236 if(new_song_number==7)
ToHellWithGeorgi 0:c3c8793d0091 237 new_song_number=1;
ToHellWithGeorgi 0:c3c8793d0091 238 play_new=false;
ToHellWithGeorgi 0:c3c8793d0091 239 }
ToHellWithGeorgi 0:c3c8793d0091 240 }