Andriy Makukha
/
football_project_wo_output
football_project_wo_output
Fork of football_project by
Diff: main.cpp
- Revision:
- 12:6d313d575f84
- Parent:
- 11:d3aa5fca2330
- Child:
- 13:28332f65d14b
--- a/main.cpp Thu Apr 23 06:36:57 2015 +0000 +++ b/main.cpp Tue Jun 16 18:16:49 2015 +0000 @@ -24,6 +24,7 @@ */ #include "mbed.h" +// #include "rtos.h" #include "BLEDevice.h" #include "DFUService.h" @@ -48,10 +49,24 @@ extern "C" { -// serial_t _my_serial; + void My_UART0_IRQHandler(); + void pin_mode( PinName, PinMode ); } +// Not using "LED" or "LED1" because target NRF51822 for FOTA uses different pins. +DigitalOut led0( P0_19, 1 ); // BLE Nano Low =On +DigitalOut led1( P0_3, 0 ); // TA Baseboard High=On +// DigitalOut rts( RTS_PIN_NUMBER ); +DigitalIn cts( CTS_PIN_NUMBER, PullDown ); // We'll use as a mode switch for serial data source. TODO + +// Check if we should swap serial Rx/Tx for early rev of "Little Brain" +DigitalIn trSwp( P0_30, PullUp ); + +// Wait to settle. +int foo = (wait( 0.1 ), 0); + + // Note: From the datasheet: // PSELRXD, PSELRTS, PSELTRTS and PSELTXD must only be configured when the UART is disabled. // But a version of serial_init() erroneously enabled the uart before the setting of those, @@ -61,28 +76,25 @@ // MTSSerial now uses our MySerial instead of Serial, and now uses hw flow control by default * // * We can't change the uart interrupt vector, so we comment-out the handler in // serial_api.c, and rebuild the mbed lib for low-level hw flow control to work. +// NVIC_SetVector( UART0_IRQn, (uint32_t)My_UART0_IRQHandler ); // Might work. TODO // MTSSerialFlowControl uses "manual" (non-hardware-low-level) flow control based on its // internal buffer--Rx servicing usually is fast enough not to need hw flow control, so it's okay. // -// mts::MTSSerialFlowControl pcfc( USBTX, USBRX, RTS_PIN_NUMBER, CTS_PIN_NUMBER, 384, 2688 ); -mts::MTSSerial pcfc( USBTX, USBRX, 256, 1280, RTS_PIN_NUMBER, NC ); // 256, 2560 +// mts::MTSSerialFlowControl pcfc( (trSwp ? USBRX : USBTX), (trSwp ? USBTX : USBRX), RTS_PIN_NUMBER, CTS_PIN_NUMBER, 384, 2688 ); +mts::MTSSerial pcfc( (trSwp ? USBRX : USBTX), (trSwp ? USBTX : USBRX), 256, 1280, RTS_PIN_NUMBER, NC ); // 256, 2560 uint8_t txPayload[TXRX_BUF_LEN] = { 0 }; -DigitalOut led1( LED1 ); -// DigitalOut rts( RTS_PIN_NUMBER ); - - char deviceName[6]; // "TAF00"; Gap::address_t macAddr; Gap::addr_type_t *pAdType; -const uint8_t DevInfoServiceUUID_rev[] = -{ - (uint8_t)(GattService::UUID_DEVICE_INFORMATION_SERVICE & 0xFF), (uint8_t)(GattService::UUID_DEVICE_INFORMATION_SERVICE >> 8) -}; +// const uint8_t DevInfoServiceUUID_rev[] = +// { +// (uint8_t)(GattService::UUID_DEVICE_INFORMATION_SERVICE & 0xFF), (uint8_t)(GattService::UUID_DEVICE_INFORMATION_SERVICE >> 8) +// }; UARTService *uartServicePtr; PhoneAppIO *phoneP; @@ -150,6 +162,7 @@ void periodicCallback( void ) { + led0 = !led0; led1 = !led1; // rts = !rts; } @@ -179,12 +192,25 @@ } } +/* +void led_thread( void const *args ) +{ + while( true ) + { + led0 = !led0; + led1 = !led1; + Thread::wait( 1000 ); + } +} +*/ + int main( void ) { - led1 = 1; + // NVIC_SetVector( UART0_IRQn, (uint32_t)My_UART0_IRQHandler ); // TODO maybe try before instantiating pcfc. + Ticker ticker; ticker.attach( periodicCallback, 1 ); - + // Thread thread( led_thread ); pcfc.baud( 57600 ); @@ -198,7 +224,8 @@ ble.onDataSent( onDataSent ); /* setup advertising */ - ble.accumulateAdvertisingPayload( GapAdvertisingData::BREDR_NOT_SUPPORTED ); + ble.accumulateAdvertisingPayload( GapAdvertisingData::BREDR_NOT_SUPPORTED | + GapAdvertisingData::LE_GENERAL_DISCOVERABLE ); ble.setAdvertisingType( GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED ); // Get MAC addr so we can create a device name using it. @@ -215,8 +242,9 @@ ble.accumulateAdvertisingPayload( GapAdvertisingData::INCOMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed) ); - ble.accumulateScanResponse( GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, - (const uint8_t *)DevInfoServiceUUID_rev, sizeof(DevInfoServiceUUID_rev) ); +// Necessary? +// ble.accumulateScanResponse( GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, +// (const uint8_t *)DevInfoServiceUUID_rev, sizeof(DevInfoServiceUUID_rev) ); ble.setAdvertisingInterval( Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS( 200 ) ); ble.startAdvertising();