initial commit
Dependencies: USBDevice max32630fthr
Fork of FTHR_USB_serial by
main.cpp@1:6923b075c8d7, 2016-11-12 (annotated)
- Committer:
- switches
- Date:
- Sat Nov 12 00:34:35 2016 +0000
- Revision:
- 1:6923b075c8d7
- Parent:
- 0:60a522ae2e35
- Child:
- 2:57500e991166
Adding USB serial demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:60a522ae2e35 | 1 | #include "mbed.h" |
switches | 1:6923b075c8d7 | 2 | #include "USBSerial.h" |
switches | 0:60a522ae2e35 | 3 | |
switches | 0:60a522ae2e35 | 4 | #define MAX14690_I2C_ADDR 0x50 |
switches | 0:60a522ae2e35 | 5 | |
switches | 1:6923b075c8d7 | 6 | // Hardware serial port over DAPLink |
switches | 1:6923b075c8d7 | 7 | Serial pc(USBTX, USBRX); |
switches | 1:6923b075c8d7 | 8 | |
switches | 0:60a522ae2e35 | 9 | DigitalOut led1(LED1); |
switches | 0:60a522ae2e35 | 10 | I2C i2cm2(P5_7, P6_0); |
switches | 0:60a522ae2e35 | 11 | |
switches | 0:60a522ae2e35 | 12 | // main() runs in its own thread in the OS |
switches | 0:60a522ae2e35 | 13 | // (note the calls to Thread::wait below for delays) |
switches | 0:60a522ae2e35 | 14 | int main() |
switches | 0:60a522ae2e35 | 15 | { |
switches | 0:60a522ae2e35 | 16 | char data[5]; |
switches | 1:6923b075c8d7 | 17 | int c; |
switches | 0:60a522ae2e35 | 18 | data[0] = 0x14; // I2C address for first register (LDO2 CFG) |
switches | 0:60a522ae2e35 | 19 | data[1] = 0x00; // Dissable LDO2 |
switches | 0:60a522ae2e35 | 20 | data[2] = 0x19; // Set voltage to 3.3V |
switches | 0:60a522ae2e35 | 21 | data[3] = 0x00; // Dissable LDO3 |
switches | 0:60a522ae2e35 | 22 | data[4] = 0x19; // Set voltage to 3.3V |
switches | 0:60a522ae2e35 | 23 | i2cm2.write(MAX14690_I2C_ADDR, data, 5); |
switches | 0:60a522ae2e35 | 24 | data[1] = 0x02; // Enable LDO2 |
switches | 0:60a522ae2e35 | 25 | data[3] = 0x02; // Enable LDO3 |
switches | 0:60a522ae2e35 | 26 | i2cm2.write(MAX14690_I2C_ADDR, data, 5); |
switches | 0:60a522ae2e35 | 27 | |
switches | 1:6923b075c8d7 | 28 | // Virtual serial port over USB |
switches | 1:6923b075c8d7 | 29 | USBSerial serial; |
switches | 1:6923b075c8d7 | 30 | |
switches | 1:6923b075c8d7 | 31 | while(1) { |
switches | 1:6923b075c8d7 | 32 | c = serial.getc(); |
switches | 1:6923b075c8d7 | 33 | serial.putc(c); |
switches | 1:6923b075c8d7 | 34 | pc.putc(c); |
switches | 1:6923b075c8d7 | 35 | led1 = c & 1; |
switches | 0:60a522ae2e35 | 36 | } |
switches | 0:60a522ae2e35 | 37 | } |
switches | 0:60a522ae2e35 | 38 |