Library set up as dummy module on mbed to mimic Nordic.
comms.cpp@0:226550611f0d, 2016-12-12 (annotated)
- Committer:
- Stephen_NewVistas
- Date:
- Mon Dec 12 23:06:58 2016 +0000
- Revision:
- 0:226550611f0d
Got system working on bus, calling registered functions with ACK/NACK/RESPONSE. Need to clean up.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Stephen_NewVistas | 0:226550611f0d | 1 | #include "mbed.h" |
| Stephen_NewVistas | 0:226550611f0d | 2 | #include "comms.h" |
| Stephen_NewVistas | 0:226550611f0d | 3 | |
| Stephen_NewVistas | 0:226550611f0d | 4 | #define SERIAL1_TX PA_9 |
| Stephen_NewVistas | 0:226550611f0d | 5 | #define SERIAL1_RX PA_10 |
| Stephen_NewVistas | 0:226550611f0d | 6 | |
| Stephen_NewVistas | 0:226550611f0d | 7 | I2C i2c( D4 , D5 ); |
| Stephen_NewVistas | 0:226550611f0d | 8 | Serial pc( USBTX , USBRX ); |
| Stephen_NewVistas | 0:226550611f0d | 9 | Serial bus( SERIAL1_TX , SERIAL1_RX ); |
| Stephen_NewVistas | 0:226550611f0d | 10 | |
| Stephen_NewVistas | 0:226550611f0d | 11 | |
| Stephen_NewVistas | 0:226550611f0d | 12 | void initComms() { |
| Stephen_NewVistas | 0:226550611f0d | 13 | pc.baud( 115200 ); |
| Stephen_NewVistas | 0:226550611f0d | 14 | i2c.frequency( 400000 ); |
| Stephen_NewVistas | 0:226550611f0d | 15 | bus.baud( 115200 ); |
| Stephen_NewVistas | 0:226550611f0d | 16 | } |
| Stephen_NewVistas | 0:226550611f0d | 17 | |
| Stephen_NewVistas | 0:226550611f0d | 18 | void debugLog( char* fmt, ...) { |
| Stephen_NewVistas | 0:226550611f0d | 19 | char buf[100]; // this should really be sized appropriately |
| Stephen_NewVistas | 0:226550611f0d | 20 | // possibly in response to a call to vsnprintf() |
| Stephen_NewVistas | 0:226550611f0d | 21 | va_list vl; |
| Stephen_NewVistas | 0:226550611f0d | 22 | va_start(vl, fmt); |
| Stephen_NewVistas | 0:226550611f0d | 23 | |
| Stephen_NewVistas | 0:226550611f0d | 24 | vsnprintf( buf, sizeof( buf), fmt, vl); |
| Stephen_NewVistas | 0:226550611f0d | 25 | |
| Stephen_NewVistas | 0:226550611f0d | 26 | va_end( vl); |
| Stephen_NewVistas | 0:226550611f0d | 27 | |
| Stephen_NewVistas | 0:226550611f0d | 28 | pc.printf(buf); |
| Stephen_NewVistas | 0:226550611f0d | 29 | } |