Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SerialInterface USBDevice max32625pico
Fork of PICO_USB_I2C_SPI by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "USBSerial.h" 00004 #include "max32625pico.h" 00005 #include "SerialInterface.h" 00006 00007 #define USB_MAX_RESP_LENGTH 511 00008 #define USB_MAX_CMD_LENGTH 511 00009 00010 // configure VDDIOH to local 3.3V supply, set dipVio and swdVio to 1.8V supply 00011 MAX32625PICO pico(MAX32625PICO::IOH_3V3, MAX32625PICO::VIO_1V8, MAX32625PICO::VIO_1V8); 00012 00013 // Virtual serial port over USB 00014 USBSerial microUSB(0x0B6A, 0x4360); 00015 00016 // Serial Interfaces 00017 I2C i2c(P1_6, P1_7); 00018 SPI spi(P0_5, P0_6, P0_4); 00019 DigitalInOut gpio[] = {P0_0, P0_1, P0_2, P0_3, P4_4, P4_5, P4_6, P4_7}; 00020 AnalogIn ain[] = {AIN_0, AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, AIN_6, AIN_7}; 00021 00022 // Serial Interface Adapter 00023 SerialInterface serInt(&i2c, &spi, gpio, ain); 00024 00025 // Threads 00026 Thread threadUSB; 00027 00028 DigitalOut rLED(LED1); 00029 DigitalOut gLED(LED2); 00030 DigitalOut bLED(LED3); 00031 00032 void usb_thread() 00033 { 00034 char obuf[USB_MAX_RESP_LENGTH +1]; 00035 char ibuf[USB_MAX_CMD_LENGTH +1]; 00036 int i = 0; 00037 00038 microUSB.printf("micro USB serial port\r\n"); 00039 00040 while(1) { 00041 if (microUSB.readable()) { 00042 ibuf[i]=microUSB.getc(); 00043 if (ibuf[i]!='\r') { 00044 if (i < USB_MAX_CMD_LENGTH) { 00045 i += 1; 00046 } 00047 } else { 00048 bLED = LED_ON; 00049 if (i < USB_MAX_CMD_LENGTH) { 00050 ibuf[i]=0; 00051 // microUSB.printf("UART CMD: %s=", ibuf); 00052 serInt.call(ibuf, obuf); 00053 microUSB.printf("%s\r\n", obuf); 00054 } else { 00055 microUSB.printf("[-1]\r\n"); 00056 } 00057 i=0; 00058 bLED = LED_OFF; 00059 } 00060 } 00061 } 00062 } 00063 00064 00065 // main() runs in its own thread in the OS 00066 // (note the calls to Thread::wait below for delays) 00067 int main() 00068 { 00069 rLED = LED_ON; 00070 gLED = LED_ON; 00071 bLED = LED_OFF; 00072 00073 // Configure P4_4 through P4_7 for 3.3V I/O 00074 pico.vddioh(P4_4, MAX32625PICO::VIO_IOH); 00075 pico.vddioh(P4_5, MAX32625PICO::VIO_IOH); 00076 pico.vddioh(P4_6, MAX32625PICO::VIO_IOH); 00077 pico.vddioh(P4_7, MAX32625PICO::VIO_IOH); 00078 00079 rLED = LED_OFF; 00080 00081 // Start USB serial thread 00082 threadUSB.start(usb_thread); 00083 00084 // Start main loop 00085 while(1) { 00086 Thread::wait(500); 00087 gLED = !gLED; 00088 } 00089 } 00090
Generated on Fri Jul 15 2022 11:44:47 by
1.7.2
