From 453dab83c6a42c358e61437221a03b15956810a2 Mon Sep 17 00:00:00 2001 From: guohui Date: Thu, 31 Jul 2014 10:09:54 +0800 Subject: [PATCH] Make compatible with Due and add boards in boards.h --- libraries/BLE/aci_setup.cpp | 3 +++ libraries/BLE/boards.h | 4 +++- libraries/BLE/hal_aci_tl.cpp | 13 ++++++++++++- libraries/BLE/hal_platform.h | 13 +++++++++++++ libraries/BLE/lib_aci.cpp | 6 +++++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libraries/BLE/aci_setup.cpp b/libraries/BLE/aci_setup.cpp index ab014ee..beff032 100644 --- a/libraries/BLE/aci_setup.cpp +++ b/libraries/BLE/aci_setup.cpp @@ -63,6 +63,9 @@ static bool aci_setup_fill(aci_state_t *aci_stat, uint8_t *num_cmd_offset) //Add 2 bytes to the length byte for status byte, length for the total number of bytes memcpy(&msg_to_send, &(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset]), (aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset].buffer[0]+2)); + #elif defined(__SAM3X8E__) + memcpy(&msg_to_send, &(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset]), + (aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset].buffer[0]+2)); #endif //Put the Setup ACI message in the command queue diff --git a/libraries/BLE/boards.h b/libraries/BLE/boards.h index e1ea98d..4cf5f2b 100644 --- a/libraries/BLE/boards.h +++ b/libraries/BLE/boards.h @@ -28,7 +28,9 @@ #define BOARD_DEFAULT 0 //Use this if you do not know the board you are using or you are creating a new one #define REDBEARLAB_SHIELD_V1_1 1 //Redbearlab Bluetooth low energy shield v1.1 -#define REDBEARLAB_SHIELD_V2012_07 1 //Identical to Redbearlab v1.1 shield +#define REDBEARLAB_SHIELD_V2012_07 1 //Redbearlab Bluetooth low energy shield v2012.07 #define REDBEARLAB_SHIELD_V2 0 //Redbearlab Bluetooth low energy shield v2.x - No special handling required for pin reset same as default +#define REDBEARLAB_BLEND 0 //Redbearlab Bluetooth low energy Blend - No special handling required for pin reset same as default +#define REDBEARLAB_BLEND_MICRO 0 //Redbearlab Bluetooth low energy Blend Micro - No special handling required for pin reset same as default #endif \ No newline at end of file diff --git a/libraries/BLE/hal_aci_tl.cpp b/libraries/BLE/hal_aci_tl.cpp index c63ef67..c0358de 100644 --- a/libraries/BLE/hal_aci_tl.cpp +++ b/libraries/BLE/hal_aci_tl.cpp @@ -27,7 +27,9 @@ #include "hal_platform.h" #include "hal_aci_tl.h" #include "aci_queue.h" +#if !defined(__SAM3X8E__) #include +#endif /* PIC32 supports only MSbit transfer on SPI and the nRF8001 uses LSBit @@ -79,7 +81,7 @@ void m_aci_data_print(hal_aci_data_t *p_data) Interrupt service routine called when the RDYN line goes low. Runs the SPI transfer. */ static void m_aci_isr(void) -{ +{ hal_aci_data_t data_to_send; hal_aci_data_t received_data; @@ -345,6 +347,12 @@ void hal_aci_tl_init(aci_pins_t *a_pins, bool debug) The SPI library assumes that the hardware pins are used */ +#if defined(__SAM3X8E__) + SPI.begin (DUE_SPI_CSN); + SPI.setBitOrder (DUE_SPI_CSN, LSBFIRST); + SPI.setClockDivider(DUE_SPI_CSN, a_pins->spi_clock_divider); /* This will run the SPI at 3MHz assuming a 84MHz clock to the mcu*/ + SPI.setDataMode (DUE_SPI_CSN, SPI_MODE0); +#else SPI.begin(); //Board dependent defines #if defined (__AVR__) @@ -356,6 +364,7 @@ void hal_aci_tl_init(aci_pins_t *a_pins, bool debug) #endif SPI.setClockDivider(a_pins->spi_clock_divider); SPI.setDataMode(SPI_MODE0); +#endif /* Initialize the ACI Command queue. This must be called after the delay above. */ aci_queue_init(&aci_tx_q); @@ -428,6 +437,8 @@ static uint8_t spi_readwrite(const uint8_t aci_byte) uint8_t tmp_bits; tmp_bits = SPI.transfer(REVERSE_BITS(aci_byte)); return REVERSE_BITS(tmp_bits); +#elif defined(__SAM3X8E__) + return SPI.transfer(DUE_SPI_CSN, aci_byte, SPI_CONTINUE); #endif } diff --git a/libraries/BLE/hal_platform.h b/libraries/BLE/hal_platform.h index 91fc952..8c96abd 100644 --- a/libraries/BLE/hal_platform.h +++ b/libraries/BLE/hal_platform.h @@ -71,6 +71,19 @@ //Redefine the function for reading from flash in ChipKit #define memcpy_P memcpy +#elif defined(__SAM3X8E__) + /* definition for DUE */ + #include "Arduino.h" + + #define F(X) (X) + #undef PSTR + #define PSTR(x) (x) + #define PROGMEM + + #define pgm_read_byte_near(x) (x) + #define memcpy_P memcpy + + #define DUE_SPI_CSN 52 #endif #endif /* PLATFORM_H__ */ diff --git a/libraries/BLE/lib_aci.cpp b/libraries/BLE/lib_aci.cpp index 64e4d5c..cb31f3d 100644 --- a/libraries/BLE/lib_aci.cpp +++ b/libraries/BLE/lib_aci.cpp @@ -103,7 +103,11 @@ void lib_aci_board_init(aci_state_t *aci_stat) hal_aci_evt_t *aci_data = NULL; aci_data = (hal_aci_evt_t *)&msg_to_send; - if (REDBEARLAB_SHIELD_V1_1 == aci_stat->aci_pins.board_name) + if (REDBEARLAB_SHIELD_V1_1 == aci_stat->aci_pins.board_name + || REDBEARLAB_SHIELD_V2012_07 == aci_stat->aci_pins.board_name + || REDBEARLAB_SHIELD_V2 == aci_stat->aci_pins.board_name + || REDBEARLAB_BLEND == aci_stat->aci_pins.board_name + || REDBEARLAB_BLEND_MICRO == aci_stat->aci_pins.board_name) { /* The Bluetooth low energy Arduino shield v1.1 requires about 100ms to reset.