-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
196 lines (166 loc) · 6.89 KB
/
main.c
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
// ---------------------------------------------------------------------------------------------------------
// Functions:
// - System clock configuration.
// - Keypad configuration.
// - SPI Flash configuration.
// - Speaker configuration.
// - MIC configuration.
// - Output pin configuration.
// - UltraIO configuration.
// - Application Initiation.
// - Processing loop:
// * Codec processing(use functions in "AppFunctions.c").
// * Voice effect processing(use functions in "AppFunctions.c").
// * Keypad check and execution actions(use functions in "InputKeyActions.c").
// * Etc.
//
// Reference "Readme.txt" for more information.
// ---------------------------------------------------------------------------------------------------------
#include "App.h"
#include "Framework.h"
#include "Keypad.h"
#include "SPIFlash.h"
#include "ConfigSysClk.h"
#include "MicSpk.h"
#include "./OLED/LY096BG30.h"
#include "config.h"
#if( !defined(__CHIP_SERIES__) )
#error "Please update SDS version >= v5.0."
#endif
// SPI flash handler.
S_SPIFLASH_HANDLER g_sSpiFlash;
// Application control.
volatile UINT8 g_u8AppCtrl;
// Application handler.
S_APP g_sApp;
extern void App_Initiate(void);
extern BOOL App_ProcessPlay(void);
extern BOOL App_StopPlay(void);
extern BOOL App_ProcessRec(void);
extern BOOL App_StopRec(void);
UINT8 SPIFlash_Initiate(void)
{
UINT16 ui16Temp;
UINT32 ui32Temp;
UINT32 u32Count;
// SPI0: GPA1=SSB00, GPA2=SCLK0, GPA3=MISO0, GPA4=MOSI0
SYS->GPA_MFP =
(SYS->GPA_MFP & (~(SYS_GPA_MFP_PA0MFP_Msk|SYS_GPA_MFP_PA1MFP_Msk|SYS_GPA_MFP_PA2MFP_Msk|SYS_GPA_MFP_PA3MFP_Msk)) )
| (SYS_GPA_MFP_PA0MFP_SPI_MOSI0|SYS_GPA_MFP_PA1MFP_SPI_SCLK|SYS_GPA_MFP_PA2MFP_SPI_SSB0|SYS_GPA_MFP_PA3MFP_SPI_MISO0);
// Reset IP module
CLK_EnableModuleClock(SPI0_MODULE);
SYS_ResetModule(SPI0_RST);
SPIFlash_Open(SPI0, SPI_SS0, SPI0_CLOCK, &g_sSpiFlash );
// Make SPI flash leave power down mode if some where or some time had made it entring power down mode
SPIFlash_PowerDown(&g_sSpiFlash, FALSE);
// Check SPI flash is ready for accessing
u32Count = ui32Temp = 0;
while(u32Count!=100)
{
SPIFlash_Read(&g_sSpiFlash, 0, (PUINT8) &ui16Temp, 2);
if ( ui32Temp != (UINT32)ui16Temp )
{
ui32Temp = (UINT32)ui16Temp;
u32Count = 0;
}
else
u32Count++;
}
// The following code can be remove to save code if the flash size is not necessary for this application
SPIFlash_GetChipInfo(&g_sSpiFlash);
if (g_sSpiFlash.u32FlashSize == 0)
return 0;
// The above code can be remove to save code if the flash size is not necessary for this application
return 1;
}
void i2c_Init(void) //ericyang 20151120 add for oled i2c driver
{
CLK_EnableModuleClock(I2C0_MODULE);//ericyang 20151120
SYS_ResetModule(I2C0_RST);
SYS->GPB_MFP = (SYS->GPB_MFP & (~SYS_GPB_MFP_PB2MFP_Msk) ) | SYS_GPB_MFP_PB2MFP_I2C_SCL;
SYS->GPB_MFP = (SYS->GPB_MFP & (~SYS_GPB_MFP_PB3MFP_Msk) ) | SYS_GPB_MFP_PB3MFP_I2C_SDA;
I2C_Open(I2C0, 400000);
}
//---------------------------------------------------------------------------------------------------------
// Main Function
//---------------------------------------------------------------------------------------------------------
INT32 main()
{
SYSCLK_INITIATE(); // Configure CPU clock source and operation clock frequency.
// The configuration functions are in "SysClkConfig.h"
CLK_EnableLDO(CLK_LDOSEL_3_3V); // Enable ISD9100 interl 3.3 LDO.
if (! SPIFlash_Initiate()) // Initiate SPI interface and checking flows for accessing SPI flash.
while(1); // loop here for easy debug
OUTPUTPIN_INITIATE(); // Initiate output pin configuration.
// The output pins configurations are defined in "ConfigIO.h".
KEYPAD_INITIATE(); // Initiate keypad configurations including direct trigger key and matrix key
// The keypad configurations are defined in "ConfigIO.h".
ULTRAIO_INITIATE(); // Initiate ultraio output configurations.
// The ultraio output pin configurations are defined in "ConfigUltraIO.h"
PDMA_INITIATE(); // Initiate PDMA.
// After initiation, the PDMA engine clock NVIC are enabled.
// Use PdmaCtrl_Open() to set PDMA service channel for desired IP.
// Use PdmaCtrl_Start() to trigger PDMA operation.
// Reference "PdmaCtrl.h" for PDMA related APIs.
// PDMA_INITIATE() must be call before SPK_INITIATE() and MIC_INITIATE(), if open MIC or speaker.
SPK_INITIATE(); // Initiate speaker including pop-sound canceling.
// After initiation, the APU is paused.
// Use SPK_Resume(0) to start APU operation.
// Reference "MicSpk.h" for speaker related APIs.
MIC_INITIATE(); // Initiate MIC.
// After initiation, the ADC is paused.
// Use ADC_Resume() to start ADC operation.
// Reference "MicSpk.h" for MIC related APIs.
App_Initiate(); // Initiate application for audio decode.
i2c_Init(); //need to excute before #define I2C_IRQ
#ifdef I2C_IRQ
I2C_EnableInt(I2C0);
NVIC_EnableIRQ(I2C0_IRQn);
NVIC_SetPriority(I2C0_IRQn, 0);
#endif
#ifdef OLED_ENABLE
Init_LCD();
clear_LCD();
print_Line(0, "OscarNuLiteExEnc");
// print_Line(1, "2015.11.12 ");
// print_Line(2, "Eric Yang ");
// print_Line(3, "0.96 OLED 128x64");
#endif
while (1)
{
if ( g_u8AppCtrl&APPCTRL_RECORD )
{
if ( App_ProcessRec() == FALSE )
{
App_StopRec();
#ifdef OLED_ENABLE
print_Line(1, " REC Stop ");
#endif
}
}
else if ( g_u8AppCtrl&APPCTRL_PLAY )
{
if ( App_ProcessPlay() == FALSE )
{
App_StopPlay();
#ifdef OLED_ENABLE
print_Line(1, " PLAY Stop ");
#endif
}
}
TRIGGER_KEY_CHECK(); // Check and execute direct trigger key actions defined in "InputKeyActions.c"
// Default trigger key handler is "Default_KeyHandler()"
// The trigger key configurations are defined in "ConfigIO.h".
MATRIX_KEY_CHECK(); // Check and execute matrix key actions defined in "InputKeyActions.c"
// Default matrix key handler is "Default_KeyHandler()"
// The matrix key configurations are defined in "ConfigIO.h".
TOUCH_KEY_CHECK(); // Check and execute touch key actions defined in "InputKeyActions.c"
// Default touch key handler is "Default_KeyHandler()"
// The touch key configurations are defined in "ConfigIO.h".
}
}