]> granicus.if.org Git - esp-idf/commitdiff
fix(spi_master): make the address field more intuitive to use.
authormichael <xiaoxufeng@espressif.com>
Tue, 1 Aug 2017 08:00:58 +0000 (16:00 +0800)
committermichael <xiaoxufeng@espressif.com>
Tue, 15 Aug 2017 06:49:31 +0000 (14:49 +0800)
The address field should be placed at the highest bits of address and slv_wr_status registers. Instead of breaking the address into two parts and fill in each register, move the address to the highest bits and write to the registers respectively.

Breaking change: if you fill-in the SPI address filed in a previous version in some way and it works correctly, you still have to rewrite the address, in a more intuitive way.

components/driver/include/driver/spi_master.h
components/driver/spi_master.c
components/driver/test/test_spi_master.c
components/soc/esp32/include/soc/spi_struct.h

index 79eb52d36d5c5e5fb859e24dde8f889cc143fc00..b65caa6ec8a73d4bd273211bcd685f0aa8bc3162 100644 (file)
@@ -71,8 +71,10 @@ typedef struct {
  */
 struct spi_transaction_t {
     uint32_t flags;                 ///< Bitwise OR of SPI_TRANS_* flags
-    uint16_t command;               ///< Command data. Specific length was given when device was added to the bus.
-    uint64_t address;               ///< Address. Specific length was given when device was added to the bus.
+    uint16_t command;               ///< Command data, of which the length is set in the command_bits of spi_device_interface_config_t.
+    uint64_t addr;                  ///< Address data, of which the length is set in the address_bits of spi_device_interface_config_t.
+                                    ///< <b>NOTE: this field is re-written to be used in a new way.</b> 
+                                    ///< - Example: write 0x123400 and address_bits=24 to send address of 0x12, 0x34, 0x00.  
     size_t length;                  ///< Total data length, in bits
     size_t rxlength;                ///< Total data length received, if different from length. (0 defaults this to the value of ``length``)
     void *user;                     ///< User-defined variable. Can be used to store eg transaction ID.
index f34d5bc90ca92ddf0aa76a2812a51c56ff06a91b..6bec4eaee498dce6ee8b38f5529ce0e27b283a78 100644 (file)
@@ -548,11 +548,16 @@ static void IRAM_ATTR spi_intr(void *arg)
         host->hw->miso_dlen.usr_miso_dbitlen=trans->rxlength-1;
 
         host->hw->user2.usr_command_value=trans->command;
+               
+        // NOTE: WE CHANGED THE WAY USING ADDRESS FIELD. Now address should be filled in, in the following format:
+        // Example: write 0x123400 and address_bits=24 to send address 0x12, 0x34, 0x00 (in previous version, you may have to write 0x12340000)
+        // shift the address to MSB of addr (and maybe slv_wr_status) register. 
+        // output address will be sent from MSB to LSB of addr register, then comes the MSB to LSB of slv_wr_status register. 
         if (dev->cfg.address_bits>32) {
-            host->hw->addr=trans->address >> 32;
-            host->hw->slv_wr_status=trans->address & 0xffffffff;
+            host->hw->addr = trans->addr >> (dev->cfg.address_bits - 32);
+            host->hw->slv_wr_status = trans->addr << (64 - dev->cfg.address_bits);
         } else {
-            host->hw->addr=trans->address & 0xffffffff;
+            host->hw->addr = trans->addr << (32 - dev->cfg.address_bits);
         }
         host->hw->user.usr_mosi=(trans->tx_buffer!=NULL || (trans->flags & SPI_TRANS_USE_TXDATA))?1:0;
         host->hw->user.usr_miso=(trans->rx_buffer!=NULL || (trans->flags & SPI_TRANS_USE_RXDATA))?1:0;
index 45314b7086646118b1995dffbeaf123f74bd04c8..9b4b830ec118348ff63250c560dc59c030e25e67 100644 (file)
@@ -131,7 +131,7 @@ static void spi_test(spi_device_handle_t handle, int num_bytes) {
     t.length=num_bytes*8;
     t.tx_buffer=sendbuf;
     t.rx_buffer=recvbuf;
-    t.address=0xA00000000000000FL;
+    t.addr=0xA00000000000000FL;
     t.command=0x55;
 
     printf("Transmitting %d bytes...\n", num_bytes);
index 149782ff19d89152fb7c2e2eb11861306c721e73..10bdcbb1c1aceb27338fb2467aa2c1ad33fc8bc2 100644 (file)
@@ -36,7 +36,7 @@ typedef volatile struct {
         };
         uint32_t val;
     } cmd;
-    uint32_t addr;                                          /*addr to slave / from master */
+    uint32_t addr;                                          /*addr to slave / from master. SPI transfer from the MSB to the LSB. If length > 32 bits, then address continues from MSB of slv_wr_status.*/
     union {
         struct {
             uint32_t reserved0:         10;                 /*reserved*/