[f80c36]: main.c Maximize Restore History

Download this file

main.c    153 lines (123 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Copyright (C) 2011 Georg Ottinger
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* MAIN.C file
*
* Author: Georg Ottinger
* Project: OggStreamer
* Date:
*/
#include "includes.h"
code const unsigned char magic_key[4] = "OgGi";
unsigned short loopcounter;
void main()
{
unsigned char state,c;
unsigned char magic_key_check[4], magic_key_index, cmd_enabled;
InitGPIO();
InitCPUSpeed();
UART2_Init((u32)UART_BAUDRATE,
UART2_WORDLENGTH_8D,
UART2_STOPBITS_1,
UART2_PARITY_NO,
UART2_SYNCMODE_CLOCK_DISABLE,
UART2_MODE_TXRX_ENABLE);
InitVS1053();
SetLedRight(0xAA);
SetLedRight(0x55);
SetLedLeft(0xAA);
SetLedLeft(0x55);
VS1053SetGPIO(~0xA0);
VS1053SetGPIO(~0x50);
state = STATE_IDLE;
cmd_enabled = 0;
while (1)
{
loopcounter++;
if(UART2_IsRX())
{
c=UART2_ReceiveData8();
if(c == magic_key[0])
{
magic_key_index = 0;
}
magic_key_check[magic_key_index++] = c;
if(memcmp(magic_key_check, magic_key, 4) == 0)
{
cmd_enabled = 1;
}
if(cmd_enabled)
{
switch(c)
{
case 'b':
if(state == STATE_IDLE)
{
state = STATE_STARTSTREAMING;
}
break;
case 'e':
if(state == STATE_STREAMING)
{
state = STATE_STOPSTREAMING_STAGE1;
}
cmd_enabled = 0;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
c -= '0';
c <<= 4;
VS1053SetGPIO(~c);
break;
default:
break;
}
}
}
switch(state)
{
case STATE_IDLE:
break;
case STATE_STARTSTREAMING:
InitVS1053();
VS1053LoadPlugin();
state = STATE_STREAMING;
break;
case STATE_STREAMING:
VS1053ReadVol();
VS1053StreamOgg();
break;
case STATE_STOPSTREAMING_STAGE1:
VS1053WriteRegister(VS1053_REG_AICTRL3,BIT(0)); //Stop Streaming Command
state = STATE_STOPSTREAMING_STAGE2;
break;
case STATE_STOPSTREAMING_STAGE2:
VS1053StreamOgg();
if(VS1053ReadRegister(VS1053_REG_AICTRL3) & BIT(1)) // encoder finished writing to buffer
{
VS1053StreamOggClose();
state = STATE_IDLE;
}
break;
default:
break;
}
}
}