from bytes to bits
This commit is contained in:
parent
523ea45acd
commit
5649753dfc
|
@ -3,7 +3,7 @@
|
|||
|
||||
struct Wave
|
||||
{
|
||||
char signal[25];
|
||||
unsigned short signal;
|
||||
unsigned short length;
|
||||
};
|
||||
|
||||
|
|
56
src/main.c
56
src/main.c
|
@ -1,46 +1,46 @@
|
|||
#include "main.h"
|
||||
#include "sound4calc.h"
|
||||
#include <timer.h>
|
||||
|
||||
#include <display.h>
|
||||
#include <keyboard.h>
|
||||
#include "string.h"
|
||||
//#define PI 3.141592653584
|
||||
|
||||
void DrawKeyF(char* str, unsigned char keyF)
|
||||
{
|
||||
dprint((keyF-1)*22 + 8 - 2*strlen(str), 55, "%s", str);
|
||||
dreverse_area((keyF-1)*22 - 2 , 54, keyF * 21, 64);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int key = 0;
|
||||
unsigned short place = 0;
|
||||
unsigned char str[16];
|
||||
|
||||
// initialisation to play
|
||||
note.freq = 440;
|
||||
note.wave.signal[0] = 0;
|
||||
note.wave.signal = 0;
|
||||
note.duration = 2000;
|
||||
|
||||
note.wave.length = 16; // 2 bytes long
|
||||
|
||||
InitPorts();
|
||||
|
||||
while(1)
|
||||
{
|
||||
note.wave.length = place;
|
||||
|
||||
dclear();
|
||||
|
||||
dprint(1, 1, "%d", note.freq);
|
||||
dprint(1, 10, "%s", note.wave.signal);
|
||||
dprint(1, 20, "%d", note.wave.length);
|
||||
dprint(1, 1, "frq = %d", note.freq);
|
||||
dprint(1, 10, "%s", str);
|
||||
dprint(1, 20, "%d", note.wave.signal);
|
||||
dprint(1, 30, "%d", place);
|
||||
dprint(1, 40, "length %d", note.wave.length);
|
||||
|
||||
DrawKeyF("not", 1);
|
||||
DrawKeyF("seq", 2);
|
||||
DrawKeyF("_", 5);
|
||||
DrawKeyF("-", 6);
|
||||
DrawKeyF("1", 5);
|
||||
DrawKeyF("0", 6);
|
||||
|
||||
dupdate();
|
||||
|
||||
str[place] = 0;
|
||||
note.wave.signal = atob(str, note.wave.length);
|
||||
|
||||
key = getkey();
|
||||
|
||||
switch(key)
|
||||
|
@ -50,9 +50,13 @@ int main(void)
|
|||
case KEY_UP : note.freq+=10; break;
|
||||
case KEY_DOWN : note.freq-=10; break;
|
||||
|
||||
case KEY_F5 : *(note.wave.signal+place++) = '_'; *(note.wave.signal+place) = 0; break;
|
||||
case KEY_F6 : *(note.wave.signal+place++) = '-'; *(note.wave.signal+place) = 0; break;
|
||||
case KEY_DEL : place=(place>0 ? place - 1 : 0); *(note.wave.signal+place) = 0; break;
|
||||
case KEY_F5 : str[place] = '1'; place=(place < note.wave.signal ? place + 1 : place); break;
|
||||
case KEY_F6 : str[place] = '0'; place=(place < note.wave.signal ? place + 1 : place); break;
|
||||
case KEY_DEL : place=(place>0 ? place - 1 : 0); break;
|
||||
|
||||
//case KEY_F5 : *(note.wave.signal+place++) = 255; *(note.wave.signal+place) = 0; break;
|
||||
//case KEY_F6 : *(note.wave.signal+place++) = 240; *(note.wave.signal+place) = 0; break;
|
||||
//case KEY_DEL : place=(place>0 ? place - 1 : 0); *(note.wave.signal+place) = 0; break;
|
||||
|
||||
case KEY_F1 : CallNote(); break;
|
||||
case KEY_F2 : CallSequence(); break;
|
||||
|
@ -62,3 +66,19 @@ int main(void)
|
|||
}
|
||||
return 1; // this point is never reached
|
||||
}
|
||||
|
||||
void DrawKeyF(char* str, unsigned char keyF)
|
||||
{
|
||||
dprint((keyF-1)*21 + 11 - 3*strlen(str), 55, "%s", str);
|
||||
dreverse_area((keyF-1)*21 + 1 , 54, keyF * 21 - 1, 64);
|
||||
}
|
||||
|
||||
int atob(unsigned char* str, int bit_nb)
|
||||
{
|
||||
unsigned int tmp = 0;
|
||||
for(int i = 0; i < bit_nb; i++)
|
||||
{
|
||||
tmp += ((str[i] - '0') * (0x1 << (bit_nb - i - 1)));
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,10 @@ static struct {
|
|||
} seq[] = {
|
||||
{ 440, 500 },
|
||||
{ 392, 500 },
|
||||
{ 349, 1000 },
|
||||
{ 349, 1000 },
|
||||
{ 262, 500 },
|
||||
{ 294, 500 },
|
||||
{ 262, 1000 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
|
||||
|
@ -72,9 +75,12 @@ void PlayNote()
|
|||
{
|
||||
static int x = 0;
|
||||
|
||||
PutPinState(note.wave.signal[x]=='-');
|
||||
PutPinState((note.wave.signal >> x) & 0x01);
|
||||
x = x + 1;
|
||||
if(!(note.wave.signal[x])) x = 0;
|
||||
if(x>=note.wave.length)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -82,8 +88,11 @@ void PlayNote()
|
|||
put the pin at the level wanted
|
||||
|
||||
SH4 :
|
||||
state 0 : xxxx.01xx
|
||||
state 1 : xxxx.10xx
|
||||
state 0 : xxxx.x0xx
|
||||
state 1 : xxxx.x1xx
|
||||
|
||||
We can put 2 other state but the sound volume is too high
|
||||
|
||||
SH3 :
|
||||
state 0 : xxxx.xxx0
|
||||
state 1 : xxxx.xxx1
|
||||
|
@ -98,7 +107,7 @@ void PutPinState(char level)
|
|||
}
|
||||
else
|
||||
{
|
||||
*(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xF3) | (0x4 << level);
|
||||
*(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xF3) | (0x2 << level);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,14 +148,12 @@ void InitPorts()
|
|||
*(volatile unsigned char*)SH7305_PUDR |= 0x0C;
|
||||
// set port J bit 2 to output
|
||||
*(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x0030 ) | 0x0010;
|
||||
|
||||
// set port J bit 3 to input
|
||||
*(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x00C0 ) | 0x0080;
|
||||
|
||||
/*
|
||||
// set port J bit 2 to output mode
|
||||
*(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x0030 ) | 0x0010;
|
||||
// set port J bit 3 to output mode
|
||||
*(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x00C0 ) | 0x0040;
|
||||
*/
|
||||
//*(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x00C0 ) | 0x0040;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue