09-F746-Demo_HID_MSC (STM32F746)

Mit diesem Demo-Projekt wird der USB-DualMode (MSC+HID) des STM32F746-Discovery-Board getestet.

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
//--------------------------------------------------------------
// File     : main.c
// Datum    : 12.07.2015
// Version  : 1.0
// Autor    : UB
// EMail    : mc-4u(@)t-online.de
// Web      : www.mikrocontroller-4u.de
// CPU      : STM32F746
// Board    : STM32F746-Discovery-Board
// IDE      : OpenSTM32
// GCC      : 4.9 2015q2
// Module   : CubeHAL
// Funktion : Hauptprogramm
//--------------------------------------------------------------
 
 
#include "stm32_ub_system.h"
#include "stm32_ub_lcd_480x272.h"
#include "stm32_ub_font.h"
#include "stm32_ub_usb_hid_host.h"
#include "stm32_ub_usb_msc_host.h"
#include "stm32_ub_fatfs.h"
 
//--------------------------------------------------------------
USB_MSC_HOST_STATUS_t msc_status;
USB_HID_HOST_STATUS_t hid_status;
 
 
void clearDisplay(void);
void usbDemo(void);
void mouseDemo(void);
void keyboardDemo(void);
 
 
int main(void)
{
  // init vom System
  UB_System_Init();
 
  // init vom LCD
  UB_LCD_Init();
  UB_LCD_LayerInit_Fullscreen();
  UB_LCD_SetLayer_2();
 
  clearDisplay();
 
 
  // init USB-HID (USB-FS)
  UB_USB_HID_HOST_Init();
 
  // init USB-MSC (USB-HS)
  UB_USB_MSC_HOST_Init();
  UB_Fatfs_Init();
 
  while(1) {
	hid_status=UB_USB_HID_HOST_Do();
    UB_USB_MSC_HOST_Do();
    if(UB_Fatfs_CheckMedia(USB_0)==FATFS_OK) usbDemo();
    if(hid_status==USB_HID_MOUSE_CONNECTED) mouseDemo();
    if(hid_status==USB_HID_KEYBOARD_CONNECTED) keyboardDemo();
 
 
  }
}
 
 
void clearDisplay(void)
{
	UB_LCD_FillLayer(RGB_COL_GREEN);
	UB_Font_DrawString(10,20,"F746 USB-MSC/HID-Demo (09.08.2015 / UB)",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);
#ifdef USE_USB_FS
  #ifdef USE_USB_HS
	UB_Font_DrawString(10,60,"HID at CN13 and MSC at CN12",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
	UB_Font_DrawString(10,120,"please insert USB-Drive or USB-Keyboard/Mouse",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
  #else
	UB_Font_DrawString(10,60,"please define USE_USB_FS and USE_USB_HS",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
	while(1);
  #endif
#else
	UB_Font_DrawString(10,60,"please define USE_USB_FS and USE_USB_HS",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
	while(1);
#endif
 
}
 
void usbDemo(void)
{
	FIL myFile;
	FATFS_t check;
 
	UB_LCD_FillLayer(RGB_COL_GREEN);
	UB_Font_DrawString(10,20,"USB-Demo",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);
 
   	// Media mounten
   	if(UB_Fatfs_Mount(USB_0)==FATFS_OK) {
      UB_Font_DrawString(10,60,"mount ok",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
      // File zum schreiben im root neu anlegen
      if(UB_Fatfs_OpenFile(&myFile, "0:/USB_File.txt", F_WR_CLEAR)==FATFS_OK) {
        UB_Font_DrawString(10,80,"file open : USB_File.txt",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
    	// ein paar Textzeilen in das File schreiben
        UB_Fatfs_WriteString(&myFile,"Test der WriteString-Funktion");
        UB_Fatfs_WriteString(&myFile,"hier Zeile zwei");
        check=UB_Fatfs_WriteString(&myFile,"ENDE");
        if(check==FATFS_OK) {
        	UB_Font_DrawString(10,100,"write in file : ok",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
        }
        else {
        	UB_Font_DrawString(10,100,"write in file : error",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
        }
        // File schliessen
        UB_Fatfs_CloseFile(&myFile);
        UB_Font_DrawString(10,120,"file closed",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
      }
      // Media unmounten
      UB_Fatfs_UnMount(USB_0);
      UB_Font_DrawString(10,140,"device unmounted",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
    }
   	else UB_Font_DrawString(10,60,"mount error",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
 
   	UB_Font_DrawString(10,200,"please unplug USB-Device...",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
 
	do {
		UB_USB_HID_HOST_Do();
		msc_status=UB_USB_MSC_HOST_Do();
	}while(msc_status==USB_MSC_DEV_CONNECTED);
 
	clearDisplay();
}
 
void mouseDemo(void)
{
	char buf[50];
	uint8_t check;
 
	UB_LCD_FillLayer(RGB_COL_GREEN);
	UB_Font_DrawString(10,20,"Mouse-Demo",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);
	do {
		hid_status=UB_USB_HID_HOST_Do();
		UB_USB_MSC_HOST_Do();
		check=UB_USB_HID_HOST_GetMouse();
		if(check>0) {
		  UB_Font_DrawString(10,60,"Position :",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
		  sprintf(buf,"X= %d , Y= %d    ",USB_MOUSE_DATA.xpos, USB_MOUSE_DATA.ypos);
		  UB_Font_DrawString(10,80,buf,&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
 
		  UB_Font_DrawString(10,120,"Buttons :",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
		  sprintf(buf,"1= %d , 2= %d , 3=%d   ",USB_MOUSE_DATA.btn_left, USB_MOUSE_DATA.btn_right , USB_MOUSE_DATA.btn_center);
		  UB_Font_DrawString(10,140,buf,&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
		}
 
	}while(hid_status==USB_HID_MOUSE_CONNECTED);
 
	clearDisplay();
}
 
void keyboardDemo(void)
{
	uint8_t key;
	uint16_t xp=0,yp=80;
 
	UB_LCD_FillLayer(RGB_COL_GREEN);
	UB_Font_DrawString(10,20,"Keyboard-Demo",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);
	UB_Font_DrawString(10,60,"Text :",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);
	do {
		hid_status=UB_USB_HID_HOST_Do();
		UB_USB_MSC_HOST_Do();
		key=UB_USB_HID_HOST_GetKey();
		if((key>=32) && (key<=128)) { UB_Font_DrawChar(xp,yp,key,&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); xp+=Arial_10x15.width; if(xp>460) {
			  xp=0;
			  yp+=Arial_10x15.height;
		  }
		}
 
	}while(hid_status==USB_HID_KEYBOARD_CONNECTED);
 
	clearDisplay();
}

Hier der komplette OpenSTM32-Projektordner zum Download :


Wie hat Dir dieser Artikel gefallen?

1 Stern2 Sterne3 Sterne4 Sterne5 Sterne (Noch keine Bewertungen)
Loading...

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert