Modified mbed library sources only for STM32F030K6, LQFP32 (0.8mm pitch) package, 32K Flash, 4K SRAM. Compiler target: Nucleo 32F030R8

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Thu Jun 11 09:15:08 2015 +0100
Parent:
565:536c9fb088a0
Commit message:
Synchronized with git revision 81af347389b2b87a85b1826ac315c8120e1db1a9

Full URL: https://github.com/mbedmicro/mbed/commit/81af347389b2b87a85b1826ac315c8120e1db1a9/

SPI - transfer() unification

Changed in this revision

api/I2C.h Show annotated file Show diff for this revision Revisions of this file
api/SPI.h Show annotated file Show diff for this revision Revisions of this file
api/SerialBase.h Show annotated file Show diff for this revision Revisions of this file
api/TimerEvent.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/api/I2C.h	Wed Jun 10 10:00:08 2015 +0100
+++ b/api/I2C.h	Thu Jun 11 09:15:08 2015 +0100
@@ -141,9 +141,9 @@
      *
      * @param address   8/10 bit I2c slave address
      * @param tx_buffer The TX buffer with data to be transfered
-     * @param tx_length The length of TX buffer
+     * @param tx_length The length of TX buffer in bytes
      * @param rx_buffer The RX buffer which is used for received data
-     * @param rx_length The length of RX buffer
+     * @param rx_length The length of RX buffer in bytes
      * @param event     The logical OR of events to modify
      * @param callback  The event callback function
      * @param repeated Repeated start, true - do not send stop at end
--- a/api/SPI.h	Wed Jun 10 10:00:08 2015 +0100
+++ b/api/SPI.h	Thu Jun 11 09:15:08 2015 +0100
@@ -115,48 +115,21 @@
      *
      * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
      *                  the default SPI value is sent
-     * @param tx_length The length of TX buffer
-     * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
-     *                  received data are ignored
-     * @param rx_length The length of RX buffer
-     * @param callback  The event callback function
-     * @param event     The logical OR of events to modify
-     * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
-     */
-    virtual int transfer(const uint8_t *tx_buffer, int tx_length, uint8_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
-        return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 8, callback, event);
-    }
-
-    /** Start non-blocking SPI transfer using 16bit buffers.
-     *
-     * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
-     *                  the default SPI value is sent
-     * @param tx_length The length of TX buffer
+     * @param tx_length The length of TX buffer in bytes
      * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
      *                  received data are ignored
-     * @param rx_length The length of RX buffer
+     * @param rx_length The length of RX buffer in bytes
      * @param callback  The event callback function
-     * @param event     The logical OR of events to modify
+     * @param event     The logical OR of events to modify. Look at spi hal header file for SPI events.
      * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
      */
-    virtual int transfer(const uint16_t *tx_buffer, int tx_length, uint16_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
-        return transfer(tx_buffer, tx_length, rx_buffer, rx_length, 16, callback, event);
-    }
-
-    /** Start non-blocking SPI transfer using 32bit buffers.
-     *
-     * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
-     *                  the default SPI value is sent
-     * @param tx_length The length of TX buffer
-     * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
-     *                  received data are ignored
-     * @param rx_length The length of RX buffer
-     * @param callback  The event callback function
-     * @param event     The logical OR of events to modify
-     * @return Zero if the transfer has started, or -1 if SPI peripheral is busy
-     */
-    virtual int transfer(const uint32_t *tx_buffer, int tx_length, uint32_t *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE)  {
-        return transfer((void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length, 32, callback, event);
+    template<typename Type>
+    int transfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
+        if (spi_active(&_spi)) {
+            return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
+        }
+        start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
+        return 0;
     }
 
     /** Abort the on-going SPI transfer, and continue with transfer's in the queue if any.
@@ -188,10 +161,10 @@
      *
      * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
      *                  the default SPI value is sent
-     * @param tx_length The length of TX buffer
+     * @param tx_length The length of TX buffer in bytes
      * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
      *                  received data are ignored
-     * @param rx_length The length of RX buffer
+     * @param rx_length The length of RX buffer in bytes
      * @param bit_width The buffers element width
      * @param callback  The event callback function
      * @param event     The logical OR of events to modify
@@ -203,10 +176,10 @@
      *
      * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
      *                  the default SPI value is sent
-     * @param tx_length The length of TX buffer
+     * @param tx_length The length of TX buffer in bytes
      * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
      *                  received data are ignored
-     * @param rx_length The length of RX buffer
+     * @param rx_length The length of RX buffer in bytes
      * @param bit_width The buffers element width
      * @param callback  The event callback function
      * @param event     The logical OR of events to modify
@@ -218,10 +191,10 @@
      *
      * @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
      *                  the default SPI value is sent
-     * @param tx_length The length of TX buffer
+     * @param tx_length The length of TX buffer in bytes
      * @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
      *                  received data are ignored
-     * @param rx_length The length of RX buffer
+     * @param rx_length The length of RX buffer in bytes
      * @param bit_width The buffers element width
      * @param callback  The event callback function
      * @param event     The logical OR of events to modify
--- a/api/SerialBase.h	Wed Jun 10 10:00:08 2015 +0100
+++ b/api/SerialBase.h	Thu Jun 11 09:15:08 2015 +0100
@@ -131,7 +131,7 @@
     /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
      *
      *  @param buffer   The buffer where received data will be stored
-     *  @param length   The buffer length
+     *  @param length   The buffer length in bytes
      *  @param callback The event callback function
      *  @param event    The logical OR of TX events
      */
@@ -140,7 +140,7 @@
     /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
      *
      *  @param buffer   The buffer where received data will be stored
-     *  @param length   The buffer length
+     *  @param length   The buffer length in bytes
      *  @param callback The event callback function
      *  @param event    The logical OR of TX events
      */
@@ -153,7 +153,7 @@
     /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
      *
      *  @param buffer     The buffer where received data will be stored
-     *  @param length     The buffer length
+     *  @param length     The buffer length in bytes
      *  @param callback   The event callback function
      *  @param event      The logical OR of RX events
      *  @param char_match The matching character
@@ -163,7 +163,7 @@
     /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
      *
      *  @param buffer     The buffer where received data will be stored
-     *  @param length     The buffer length
+     *  @param length     The buffer length in bytes
      *  @param callback   The event callback function
      *  @param event      The logical OR of RX events
      *  @param char_match The matching character
--- a/api/TimerEvent.h	Wed Jun 10 10:00:08 2015 +0100
+++ b/api/TimerEvent.h	Thu Jun 11 09:15:08 2015 +0100
@@ -17,6 +17,7 @@
 #define MBED_TIMEREVENT_H
 
 #include "ticker_api.h"
+#include "us_ticker_api.h"
 
 namespace mbed {
 
--- a/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c	Wed Jun 10 10:00:08 2015 +0100
+++ b/targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/spi_api.c	Thu Jun 11 09:15:08 2015 +0100
@@ -404,9 +404,6 @@
     uint32_t i;
     uint16_t *tx_ptr = (uint16_t *) tx;
 
-    tx_length *= (bit_width >> 3);
-    rx_length *= (bit_width >> 3);
-
     obj->tx_buff.buffer = (void *)tx;
     obj->rx_buff.buffer = rx;
     obj->tx_buff.length = tx_length;
@@ -951,11 +948,6 @@
     spi_enable_event(obj, SPI_EVENT_ALL, false);
     spi_enable_event(obj, event, true);
 
-    /* Be tricky on how we handle increased bit widths in the buffer... Handling on byte-basis */
-    // div 8 = shift right 3
-    tx_length = tx_length * (bit_width >> 3);
-    rx_length = rx_length * (bit_width >> 3);
-
     // Set the sleep mode
     blockSleepMode(SPI_LEAST_ACTIVE_SLEEPMODE);