cours 1

Dependencies:   mbed USBDevice

Files at this revision

API Documentation at this revision

Comitter:
kanope_benny
Date:
Thu Oct 01 12:11:56 2020 +0000
Parent:
8:c6ec6b9f6a55
Commit message:
update

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
diff -r c6ec6b9f6a55 -r 41207561508d main.cpp
--- a/main.cpp	Thu Sep 17 12:51:11 2020 +0000
+++ b/main.cpp	Thu Oct 01 12:11:56 2020 +0000
@@ -1,115 +1,77 @@
-// Hello World example for the USBMIDI library
-#if 1 
+#define TEST_BLINKY     0
+#define TEST_USB_SERIAL 0
+#define TEST_USB_SERIAL_BUT 1
 
- 
-#include "mbed.h"
+#if TEST_USB_SERIAL_BUT
+
+#include "main.h"
 #include "USBSerial.h"
 
+DigitalIn but( PB_9 );
+int       but_input = 0 ; 
 
-void setup(void)
-{
-    RCC_ClkInitTypeDef RCC_ClkInitStruct;
-    RCC_OscInitTypeDef RCC_OscInitStruct;
- 
-    RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
-    RCC_OscInitStruct.HSEState =        RCC_HSE_ON;
+int main(){
     
-    RCC_OscInitStruct.LSIState =        RCC_LSI_ON;
-    RCC_OscInitStruct.PLL.PLLState =    RCC_PLL_ON;
-    RCC_OscInitStruct.PLL.PLLSource =   RCC_PLLSOURCE_HSE;
-    
-RCC_OscInitStruct.PLL.PLLM            = 25;             // VCO input clock = 1 MHz (25 MHz / 25)
-RCC_OscInitStruct.PLL.PLLN            = 192;           // VCO output clock = 192 MHz (1 MHz * 192)
-RCC_OscInitStruct.PLL.PLLP            = RCC_PLLP_DIV2; // PLLCLK = 96 MHz (192 MHz / 2)
-RCC_OscInitStruct.PLL.PLLQ            = 4;             // USB clock = 48 MHz (192 MHz / 4) --> Good for USB
-  
-  HAL_RCC_OscConfig(&RCC_OscInitStruct);
- 
-    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
-    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
-    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
+    setup();
     
-    SystemCoreClockUpdate();
-    SystemCoreClock = 96000000;
+    USBSerial usb_pc;
     
-    //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1);        // output SYSCLOCK to pin PC9 to monitor frequency
+    while( 1 ){
+        
+        but_input = but ; 
+        usb_pc.printf(" but_input = %d \n", but_input);
+        wait_ms( 200 ); 
+    }
 }
 
- 
-
-DigitalOut myled(PC_13);
-
-int main() {    
-
-    setup();
-
-    USBSerial pc;
-         
-         
-    while (1) {    
-       pc.printf("\ncalisse de guidoune!");
-       myled = !myled; // LED 
-        wait_ms( 100 ); 
-    }
-} 
-
-
 #endif 
 
-#if 0 
+
+
+#if TEST_USB_SERIAL
+
+#include "main.h"
+#include "USBSerial.h"
 
-#include "mbed.h"
-#include "USBMIDI.h"
+int main(){
+    
+    setup();
+    
+    USBSerial usb_pc;
+    
+    while( 1 ){
+        usb_pc.printf(" USB serial test \n");
+        wait_ms( 200 ); 
+    }
+}
+
+#endif 
+
+
+#if TEST_BLINKY
 
 
-void setup(void)
-{
-    RCC_ClkInitTypeDef RCC_ClkInitStruct;
-    RCC_OscInitTypeDef RCC_OscInitStruct;
- 
-    RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
-    RCC_OscInitStruct.HSEState =        RCC_HSE_ON;
+#include "main.h"
+
+DigitalOut myled( PC_13 ); 
+
+
+int main(){
     
-    RCC_OscInitStruct.LSIState =        RCC_LSI_ON;
-    RCC_OscInitStruct.PLL.PLLState =    RCC_PLL_ON;
-    RCC_OscInitStruct.PLL.PLLSource =   RCC_PLLSOURCE_HSE;
+    setup();
     
-RCC_OscInitStruct.PLL.PLLM            = 25;             // VCO input clock = 1 MHz (25 MHz / 25)
-RCC_OscInitStruct.PLL.PLLN            = 192;           // VCO output clock = 192 MHz (1 MHz * 192)
-RCC_OscInitStruct.PLL.PLLP            = RCC_PLLP_DIV2; // PLLCLK = 96 MHz (192 MHz / 2)
-RCC_OscInitStruct.PLL.PLLQ            = 4;             // USB clock = 48 MHz (192 MHz / 4) --> Good for USB
-  
-  HAL_RCC_OscConfig(&RCC_OscInitStruct);
- 
-    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
-    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
-    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
+    while( 1 ){
+        
+        myled = 1 ;
+        
+        wait_ms( 200 ) ; 
     
-    SystemCoreClockUpdate();
-    SystemCoreClock = 96000000;
+        myled = 0 ; 
+        
+        wait_us( 200000 ) ; 
     
-    //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1);        // output SYSCLOCK to pin PC9 to monitor frequency
+    }
+    
 }
 
- 
-
-int main() {    
-
-    setup();
-
-    USBMIDI midi;
-    
-         
-    while (1) {    
-        for(int i=48; i<83; i++) {     // send some messages!
-            midi.write(MIDIMessage::NoteOn(i));
-            wait(0.25);
-            midi.write(MIDIMessage::NoteOff(i));
-            wait(0.5);
-            myled = !myled; // LED 
-        }
-    }
-}
 #endif 
\ No newline at end of file
diff -r c6ec6b9f6a55 -r 41207561508d main.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Thu Oct 01 12:11:56 2020 +0000
@@ -0,0 +1,36 @@
+
+#include "mbed.h" 
+
+ 
+
+void setup(void)
+{
+    RCC_ClkInitTypeDef RCC_ClkInitStruct;
+    RCC_OscInitTypeDef RCC_OscInitStruct;
+ 
+    RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
+    RCC_OscInitStruct.HSEState =        RCC_HSE_ON;
+    
+    RCC_OscInitStruct.LSIState =        RCC_LSI_ON;
+    RCC_OscInitStruct.PLL.PLLState =    RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource =   RCC_PLLSOURCE_HSE;
+    
+RCC_OscInitStruct.PLL.PLLM            = 25;             // VCO input clock = 1 MHz (25 MHz / 25)
+RCC_OscInitStruct.PLL.PLLN            = 192;           // VCO output clock = 192 MHz (1 MHz * 192)
+RCC_OscInitStruct.PLL.PLLP            = RCC_PLLP_DIV2; // PLLCLK = 96 MHz (192 MHz / 2)
+RCC_OscInitStruct.PLL.PLLQ            = 4;             // USB clock = 48 MHz (192 MHz / 4) --> Good for USB
+  
+  HAL_RCC_OscConfig(&RCC_OscInitStruct);
+ 
+    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
+    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
+    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
+    
+    SystemCoreClockUpdate();
+    SystemCoreClock = 96000000;
+    
+    //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1);        // output SYSCLOCK to pin PC9 to monitor frequency
+}
+
+