1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
36
37
38
39
61
62
63
64
65
66
67
68
69
70
71
72
73
74
88
89
90
95
137
138
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
171
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
211
212
213
214
221
226
227
230
231
/* ... */
#include "DIALOG.h"
#include "k_module.h"
#include "usbd_res.c"
#include "k_modules_res.h"
#include "k_storage.h"
#include "usbd_app.h"
6 includes
/* ... */
/* ... */
Includes
static void Startup(WM_HWIN hWin, uint16_t xpos, uint16_t ypos);
K_ModuleItem_Typedef usb_device =
{
10,
"USB Device",
&bmusbdevice,
Startup,
NULL,
...}
;
typedef union
{
uint32_t d32;
struct
{
uint32_t sd_mounted : 1;
uint32_t connection : 1;
...}b;
...}
USBDSettingsTypeDef;
Private typedef
#define ID_FRAMEWIN_INFO (GUI_ID_USER + 0x01)
#define ID_USB_NOT_CONNECTED (GUI_ID_USER + 0x02)
#define ID_MSD_NOT_CONNECTED (GUI_ID_USER + 0x03)
#define ID_BUTTON_USB (GUI_ID_USER + 0x04)
#define ID_IMAGE1_CONNECTED (GUI_ID_USER + 0x12)
#define ID_IMAGE1_NOT_CONNECTED (GUI_ID_USER + 0x13)
#define ID_IMAGE2_CONNECTED (GUI_ID_USER + 0x14)
#define ID_IMAGE2_NOT_CONNECTED (GUI_ID_USER + 0x15)
8 defines
Private defines
static const GUI_WIDGET_CREATE_INFO _aDialog[] =
{
{ FRAMEWIN_CreateIndirect, "USB Mass Storage Device [mSD]", ID_FRAMEWIN_INFO, 0, 0, 320, 215, 0, 0x64, 0 },
{ IMAGE_CreateIndirect, "Image", ID_USB_NOT_CONNECTED, 35, 16, 100, 100, 0, 0, 0 },
{ IMAGE_CreateIndirect, "Image", ID_MSD_NOT_CONNECTED, 160, 16, 100, 100, 0, 0, 0 },
{ BUTTON_CreateIndirect, "Connect USB ", ID_BUTTON_USB, 35, 145, 225, 35, 0, 0, 0 },
{ IMAGE_CreateIndirect, "", ID_IMAGE1_CONNECTED, 91, 77, 18, 19, 0, 0, 0 },
{ IMAGE_CreateIndirect, "", ID_IMAGE2_CONNECTED, 216, 78, 18, 19, 0, 0, 0 },
...};
USBDSettingsTypeDef USBDSettings;
Private variables
/* ... */
static void _cbMSDConnectionStatus(WM_MESSAGE * pMsg) {
static WM_HTIMER hTimerTime;
WM_HWIN hItem;
static uint8_t msd_connection_Changed = 0;
switch (pMsg->MsgId)
{
case WM_CREATE:
hTimerTime = WM_CreateTimer(pMsg->hWin, 0, 500, 0);
break;
case WM_CREATE:
case WM_TIMER:
if(msd_connection_Changed != k_StorageGetStatus(MSD_DISK_UNIT))
{
msd_connection_Changed = k_StorageGetStatus(MSD_DISK_UNIT);
if(msd_connection_Changed == 1)
{
hItem = WM_GetDialogItem(WM_GetParent(pMsg->hWin), ID_IMAGE2_CONNECTED);
IMAGE_SetBitmap(hItem, &bmconnected);
}if (msd_connection_Changed == 1) { ... }
else
{
hItem = WM_GetDialogItem(WM_GetParent(pMsg->hWin), ID_IMAGE2_CONNECTED);
IMAGE_SetBitmap(hItem, &bmnot_connected);
}else { ... }
}if (msd_connection_Changed != k_StorageGetStatus(MSD_DISK_UNIT)) { ... }
WM_RestartTimer(pMsg->Data.v, 500);
break;
case WM_TIMER:
case WM_DELETE:
msd_connection_Changed = 0;
WM_DeleteTimer(hTimerTime);
break;
case WM_DELETE:
default:
WM_DefaultProc(pMsg);default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int Id, NCode;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = pMsg->hWin;
FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0);
hItem = WM_GetDialogItem(pMsg->hWin, ID_USB_NOT_CONNECTED);
IMAGE_SetBitmap(hItem, &bmUSB_not_connected);
hItem = WM_GetDialogItem(pMsg->hWin, ID_MSD_NOT_CONNECTED);
IMAGE_SetBitmap(hItem, &bmsdcard_not_connected);
USBDSettings.b.connection = DISCONNECTED;
WM_CreateWindowAsChild(470, 0, 10, 10, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS, _cbMSDConnectionStatus , 0);
break;
case WM_INIT_DIALOG:
case WM_PAINT:
DrawRect3D(25, 05, 250, 180);
break;
case WM_PAINT:
case WM_DELETE:
USBDSTOR_Stop();
break;
case WM_DELETE:
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_USB:
if(NCode == WM_NOTIFICATION_RELEASED)
{
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_USB);
if(USBDSettings.b.connection == DISCONNECTED)
{
BUTTON_SetText(hItem, "Disconnect USB");
hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE1_CONNECTED);
IMAGE_SetBitmap(hItem, &bmconnected);
USBDSettings.b.connection = CONNECTED;
USBDSTOR_Connect();
}if (USBDSettings.b.connection == DISCONNECTED) { ... }
else
{
BUTTON_SetText(hItem, "Connect USB ");
hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE1_CONNECTED);
IMAGE_SetBitmap(hItem, &bmnot_connected);
USBDSettings.b.connection = DISCONNECTED;
USBDSTOR_Disconnect();
}else { ... }
}if (NCode == WM_NOTIFICATION_RELEASED) { ... }
break;
case ID_BUTTON_USB:
}switch (Id) { ... }
break;
case WM_NOTIFY_PARENT:
default:
WM_DefaultProc(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void Startup(WM_HWIN hWin, uint16_t xpos, uint16_t ypos)
{
USBDSTOR_Start();
GUI_CreateDialogBox(_aDialog, GUI_COUNTOF(_aDialog), _cbDialog, hWin, xpos, ypos);
}{ ... }
/* ... */
/* ... */