indent as Lephe want
This commit is contained in:
parent
2b569efdcd
commit
75824c67e5
|
@ -23,4 +23,14 @@ void PutPinState(char level);
|
|||
void PlayNote();
|
||||
void InitPorts();
|
||||
|
||||
static struct {
|
||||
int freq;
|
||||
int length_ms;
|
||||
} seq[] = {
|
||||
{ 440, 500 },
|
||||
{ 392, 500 },
|
||||
{ 349, 500 },
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
55
src/main.c
55
src/main.c
|
@ -20,45 +20,44 @@ void lect()
|
|||
|
||||
int main(void)
|
||||
{
|
||||
static int freq = 440;
|
||||
unsigned int key = 0;
|
||||
//unsigned int i=0;
|
||||
|
||||
static int freq = 440;
|
||||
unsigned int key = 0;
|
||||
//unsigned int i=0;
|
||||
InitPorts();
|
||||
|
||||
InitPorts();
|
||||
|
||||
while(1)
|
||||
while(1)
|
||||
{
|
||||
dclear();
|
||||
dclear();
|
||||
|
||||
dprint(1, 1, "%d", freq);
|
||||
dprint(1, 10, "%s", bincod);
|
||||
dprint(1, 20, "%d", place);
|
||||
dtext(1, 50, "F1 _ F2 -");
|
||||
dprint(1, 1, "%d", freq);
|
||||
dprint(1, 10, "%s", bincod);
|
||||
dprint(1, 20, "%d", place);
|
||||
dtext(1, 50, "F1 _ F2 -");
|
||||
|
||||
dupdate();
|
||||
dupdate();
|
||||
|
||||
key = getkey();
|
||||
key = getkey();
|
||||
|
||||
switch(key)
|
||||
switch(key)
|
||||
{
|
||||
case KEY_RIGHT : freq+=1; break;
|
||||
case KEY_LEFT : freq-=1; break;
|
||||
case KEY_UP : freq+=10; break;
|
||||
case KEY_DOWN : freq-=10; break;
|
||||
case KEY_RIGHT : freq+=1; break;
|
||||
case KEY_LEFT : freq-=1; break;
|
||||
case KEY_UP : freq+=10; break;
|
||||
case KEY_DOWN : freq-=10; break;
|
||||
|
||||
case KEY_F1 : *(bincod+place++) = '_'; break;
|
||||
case KEY_F2 : *(bincod+place++) = '-'; break;
|
||||
case KEY_DEL : place=(place>0 ? place - 1 : 0); *(bincod+place) = 0; break;
|
||||
case KEY_F1 : *(bincod+place++) = '_'; break;
|
||||
case KEY_F2 : *(bincod+place++) = '-'; break;
|
||||
case KEY_DEL : place=(place>0 ? place - 1 : 0); *(bincod+place) = 0; break;
|
||||
|
||||
case KEY_EXE :
|
||||
timer_start(TIMER_USER, freq*place, Clock_Hz, lect, 2*freq*place);
|
||||
break;
|
||||
case KEY_EXE :
|
||||
timer_start(TIMER_USER, freq*place, Clock_Hz, lect, 2*freq*place);
|
||||
break;
|
||||
|
||||
case KEY_EXIT :
|
||||
timer_stop(TIMER_USER);
|
||||
return 1;
|
||||
case KEY_EXIT :
|
||||
timer_stop(TIMER_USER);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1; // this point is never reached
|
||||
return 1; // this point is never reached
|
||||
}
|
||||
|
|
|
@ -3,43 +3,56 @@
|
|||
#include <timer.h> //from Gint
|
||||
|
||||
char* signal = "-_"; // simple waveform
|
||||
short Seq_signal[6] = {440,500,392,500,349,500}; // sequence signal
|
||||
|
||||
static struct {
|
||||
int freq;
|
||||
int length_ms;
|
||||
} seq[] = {
|
||||
{ 440, 500 },
|
||||
{ 392, 500 },
|
||||
{ 349, 500 },
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
|
||||
void PlaySequence()
|
||||
|
||||
void CallSequence()
|
||||
{
|
||||
static int length_end = 0;
|
||||
static int note = -2;
|
||||
static int length_end = 0;
|
||||
static int note = -1 ;
|
||||
|
||||
if(length_end<=0)
|
||||
if(length_end<=0)
|
||||
{
|
||||
note+=2;
|
||||
note++;
|
||||
|
||||
if(!Seq_signal[note])
|
||||
//Stop the timer
|
||||
if(seq[note].freq < 0)
|
||||
{
|
||||
timer_stop(TIMER_USER);
|
||||
return;
|
||||
}
|
||||
|
||||
length_end = Seq_signal[note+1];
|
||||
length_end = seq[note].freq * seq[note].length_ms / 1000;
|
||||
|
||||
timer_start(TIMER_USER, Seq_signal[note], Clock_Hz, PlaySequence, Seq_signal[note+1]);
|
||||
timer_start(TIMER_USER, 2 * seq[note].freq, Clock_Hz, CallSequence, 0));
|
||||
}
|
||||
|
||||
PlayNote();
|
||||
length_end--;
|
||||
PlayNote();
|
||||
length_end--;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
PlayNote()
|
||||
allow to make different waveforms with '-' and '_'
|
||||
*/
|
||||
void PlayNote()
|
||||
{
|
||||
static int x = 0;
|
||||
PutPinState(signal[x]=='-');
|
||||
x = x + 1;
|
||||
if(!(signal[x])) x = 0;
|
||||
static int x = 0;
|
||||
|
||||
PutPinState(signal[x]=='-');
|
||||
x = x + 1;
|
||||
if(!(signal[x])) x = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -55,15 +68,15 @@ if(!(signal[x])) x = 0;
|
|||
*/
|
||||
void PutPinState(char level)
|
||||
{
|
||||
level = !!level;
|
||||
level = !!level;
|
||||
|
||||
if(isSH3())
|
||||
if(isSH3())
|
||||
{
|
||||
*(volatile unsigned char*)SH7337_SCPDR = (*(volatile unsigned char*)SH7337_SCPDR & 0xFE) | level ;
|
||||
*(volatile unsigned char*)SH7337_SCPDR = (*(volatile unsigned char*)SH7337_SCPDR & 0xFE) | level ;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
*(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xF3) | (0x1<<(2+level));
|
||||
*(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xF3) | (0x4 << level);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,43 +88,43 @@ else
|
|||
*/
|
||||
void InitPorts()
|
||||
{
|
||||
if(isSH3())
|
||||
if(isSH3())
|
||||
{
|
||||
// initialisation of pin
|
||||
// *(volatile unsigned char*)SH7337_SCPDR |= 0x01;
|
||||
|
||||
// SCIF2 clock on (STBCR3.MSTP31)
|
||||
*(volatile unsigned char*)SH7337_STBCR3 &= ~0x02;
|
||||
*(volatile unsigned char*)SH7337_STBCR3 &= ~0x02;
|
||||
// switch off SCSMR_2.TE and SCSMR_2.RE
|
||||
*(volatile unsigned short*)SH7337_SCSCR2 &= ~0x0030;
|
||||
*(volatile unsigned short*)SH7337_SCSCR2 &= ~0x0030;
|
||||
// SCIF2 clock off (STBCR3.MSTP31)
|
||||
*(volatile unsigned char*)SH7337_STBCR3 |= 0x02;
|
||||
*(volatile unsigned char*)SH7337_STBCR3 |= 0x02;
|
||||
// set bit 6 of port G to output mode
|
||||
*(volatile unsigned short*)SH7337_PGCR = ( *(volatile unsigned short*)SH7337_PGCR & ~0x3000 ) | 0x1000;
|
||||
*(volatile unsigned short*)SH7337_PGCR = ( *(volatile unsigned short*)SH7337_PGCR & ~0x3000 ) | 0x1000;
|
||||
// set bit 5 and 6 of port G
|
||||
*(volatile unsigned char*)SH7337_PGDR |= 0x60;
|
||||
*(volatile unsigned char*)SH7337_PGDR |= 0x60;
|
||||
// set port SC bit 0 to output
|
||||
*(volatile unsigned short*)SH7337_SCPCR = ( *(volatile unsigned short*)SH7337_SCPCR & ~0x0003 ) | 0x0001;
|
||||
*(volatile unsigned short*)SH7337_SCPCR = ( *(volatile unsigned short*)SH7337_SCPCR & ~0x0003 ) | 0x0001;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// initialisation of pin
|
||||
// *(volatile unsigned char*)SH7305_PJDR |= 0x04;
|
||||
|
||||
// SCIF2 clock on (MSTPCR0.MSTP007)
|
||||
*(volatile unsigned int*)SH7305_MSTPCR0 &= ~0x00000080;
|
||||
*(volatile unsigned int*)SH7305_MSTPCR0 &= ~0x00000080;
|
||||
// switch off SCSMR_2.TE and SCSMR_2.RE
|
||||
*(volatile unsigned short*)SH7305_SCSCR &= ~0x0030;
|
||||
*(volatile unsigned short*)SH7305_SCSCR &= ~0x0030;
|
||||
// SCIF2 clock off (MSTPCR0.MSTP007)
|
||||
*(volatile unsigned int*)SH7305_MSTPCR0 |= 0x00000080;
|
||||
*(volatile unsigned int*)SH7305_MSTPCR0 |= 0x00000080;
|
||||
// set bit 3 of port U to output mode
|
||||
*(volatile unsigned short*)SH7305_PUCR = ( *(volatile unsigned short*)SH7305_PUCR & ~0x00C0 ) | 0x0040;
|
||||
*(volatile unsigned short*)SH7305_PUCR = ( *(volatile unsigned short*)SH7305_PUCR & ~0x00C0 ) | 0x0040;
|
||||
// set bit 4 and 5 of port U
|
||||
*(volatile unsigned char*)SH7305_PUDR |= 0x0C;
|
||||
*(volatile unsigned char*)SH7305_PUDR |= 0x0C;
|
||||
// set port J bit 2 to output
|
||||
*(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x0030 ) | 0x0010;
|
||||
*(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x0030 ) | 0x0010;
|
||||
// set port J bit 3 to input
|
||||
*(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x00C0 ) | 0x0080;
|
||||
*(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x00C0 ) | 0x0080;
|
||||
|
||||
/*
|
||||
// set port J bit 2 to output mode
|
||||
|
|
Loading…
Reference in New Issue