Firmware development for use with LF21
Dependencies: USBDevice max32630fthr
Fork of FTHR_USB_serial by
Revision 11:8a8562282546, committed 2017-09-26
- Comitter:
- nwaskewicz
- Date:
- Tue Sep 26 20:56:05 2017 +0000
- Parent:
- 10:aec9f740a325
- Commit message:
- updated i2c and pwm declarations
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r aec9f740a325 -r 8a8562282546 main.cpp --- a/main.cpp Fri Sep 22 18:15:14 2017 +0000 +++ b/main.cpp Tue Sep 26 20:56:05 2017 +0000 @@ -13,8 +13,9 @@ USBSerial microUSB; SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk -I2C i2c(P3_4, P3_5); +I2C *i2c; DigitalOut spicsb(P4_0); // spi csb line +PwmOut *pwm; DigitalOut p3_0(P3_0); DigitalOut p3_1(P3_1); @@ -46,7 +47,7 @@ spicsb = 1; pegasus.max14690.ldo3SetVoltage(1800); wait(1.0); - i2c.frequency(1000000); + //i2c.frequency(100000); p3_0 = 0; p3_1 = 1; @@ -91,18 +92,55 @@ wait(0.01); gLED=LED_OFF; } - // virtual int write(const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length); - else if (buf[0]=='t' && buf[1]=='e' && buf[2]=='s' && buf[3]=='t') { + + // spi transmit command + // write to SPITX_EN register and leave CS low + else if (buf[0]=='s' && buf[1]=='p' && buf[2]=='i' && buf[3]=='t') { int resp = 0; char payload[2]; char response[2]; - payload[0] = 0x5A; - payload[1] = 0xA5; + payload[0] = ascii((int)buf[5],(int)buf[6]); + payload[1] = ascii((int)buf[8],(int)buf[9]); spicsb = 0; resp = spi.write(payload, sizeof(payload), response, sizeof(response)); + microUSB.printf("ack.%i\r\n",resp); + gLED=LED_OFF; + wait(0.01); + gLED=LED_ON; + wait(0.01); + gLED=LED_OFF; + } + + // set csb high + else if (buf[0]=='c' && buf[1]=='s' && buf[2]=='b' && buf[3]=='h') { spicsb = 1; + microUSB.printf("ack\r\n"); + gLED=LED_OFF; + wait(0.01); + gLED=LED_ON; + wait(0.01); + gLED=LED_OFF; + } + + else if (buf[0]=='p' && buf[1]=='w' && buf[2]=='m' && buf[3]=='o') { + pwm = new PwmOut(P3_4); + pwm->period_us(20); + pwm->write(0.50f); - microUSB.printf("ack.%i\r\n",resp); + microUSB.printf("ack\r\n"); + gLED=LED_OFF; + wait(0.01); + gLED=LED_ON; + wait(0.01); + gLED=LED_OFF; + } + + else if (buf[0]=='t' && buf[1]=='e' && buf[2]=='s' && buf[3]=='t') { + pwm = new PwmOut(P3_4); + pwm->period(0.5f); + pwm->write(0.50f); + + microUSB.printf("ack\r\n"); gLED=LED_OFF; wait(0.01); gLED=LED_ON; @@ -127,13 +165,15 @@ wait(0.01); gLED=LED_OFF; } + // i2c write command: i2cw.addr.data else if (buf[0]=='i' && buf[1]=='2' && buf[2]=='c' && buf[3]=='w') { + i2c = new I2C(P3_4, P3_5); int response = 0; char payload[2]; payload[0] = ascii((int)buf[5],(int)buf[6]); payload[1] = ascii((int)buf[8],(int)buf[9]); - response = i2c.write(LF21_I2C_WRITE, payload, sizeof(payload)); + response = i2c->write(LF21_I2C_WRITE, payload, sizeof(payload)); microUSB.printf("ack.%i\r\n", response); gLED=LED_OFF; wait(0.01); @@ -143,13 +183,14 @@ } // i2c read command: i2cr.addr else if (buf[0]=='i' && buf[1]=='2' && buf[2]=='c' && buf[3]=='r') { + i2c = new I2C(P3_4, P3_5); int response = 0; char address[1]; char payload[1]; payload[0] = 0xFF; address[0] = ascii((int)buf[5],(int)buf[6]); - response = i2c.write(LF21_I2C_WRITE, address, sizeof(address), true); - response = i2c.read(LF21_I2C_READ, payload, sizeof(payload)); + response = i2c->write(LF21_I2C_WRITE, address, sizeof(address), true); + response = i2c->read(LF21_I2C_READ, payload, sizeof(payload)); microUSB.printf("ack.%i.%i\r\n", response, payload[0]); gLED=LED_OFF; wait(0.01); @@ -157,6 +198,7 @@ wait(0.01); gLED=LED_OFF; } + // digital pin p5_5 else if (buf[0]=='p' && buf[1]=='5' && buf[2]=='_' && buf[3]=='5') { if (buf[5]=='1') p5_5 = 1;